ahvn.klengine.vector_engine module¶
Universal vector KL engine implementation.
- class ahvn.klengine.vector_engine.VectorKLEngine(storage, inplace=True, include=None, exclude=None, filters=None, name=None, condition=None, *args, **kwargs)[源代码]¶
基类:
BaseKLEngineA vector-based search KLEngine implementation that provides multiple search interfaces.
This class extends BaseKLEngine with specialized search methods: - Vector similarity search through the default _search method - Filtered vector search through _search method - LLM-powered natural language to vector search through _search_auto method
The engine is designed to work with vector data that can be searched using semantic similarity and filtered using various metadata conditions.
- Search Methods:
_search_vector(query, topk, include, **filters): Perform vector similarity search with optional metadata filters. _search = _search_vector: Alias for _search_vector for default search behavior.
- Abstract Methods (inherited from BaseKLEngine):
_upsert(kl): Insert or update a KL in the engine. _remove(key): Remove a KL from the engine by its key (id). _clear(): Clear all KLs from the engine.
- 参数:
- __init__(storage, inplace=True, include=None, exclude=None, filters=None, name=None, condition=None, *args, **kwargs)[源代码]¶
Initialize the VectorKLEngine.
- 参数:
storage (
VectorKLStore) -- attach VectorKLEngine to a VectorKLStore (required).inplace (
bool) -- If True, search directly on storage vector database; if False, create a copied collection with included fields.include (if inplace=False) -- List of BaseUKF field names to include. If None, includes all fields. Default is None.
exclude (if inplace=False) -- List of BaseUKF field names to exclude. If None, excludes no fields. Default is None. Notice that exclude is applied after include, so if a field is in both include and exclude, it will be excluded. It is recommended to use only one of include or exclude.
filters (
Dict[str,Any]) -- global filters that will be applied to all searches.name (
Optional[str]) -- Name of the KLEngine instance. If None, defaults to "{storage.name}_vec_idx".condition (
Optional[Any]) -- Optional upsert/insert condition to apply to the KLEngine. KLs that do not satisfy the condition will be ignored. If None, all KLs are accepted.*args -- Additional positional arguments passed to VectorKLEngine.
**kwargs -- Additional keyword arguments passed to VectorKLEngine.
- batch_q_embed(encoded_queries)[源代码]¶
Embed a batch of encoded query strings using the VDB's query embedder.
- batch_k_encode_embed(kls)[源代码]¶
Encode and embed a batch of BaseUKFs using the VDB's key encoder and embedder.
- q_encode_embed(query)[源代码]¶
Encode and embed a query string using the VDB's query encoder and embedder.
- batch_q_encode_embed(queries)[源代码]¶
Encode and embed a batch of query strings using the VDB's query encoder and embedder.
- property embedding_field¶
Get the vector field name used by this engine.
- property adapter¶
Get the adapter used by this engine.