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)[source]¶

Bases: BaseKLEngine

A 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.

Parameters:
inplace: bool = True¶
__init__(storage, inplace=True, include=None, exclude=None, filters=None, name=None, condition=None, *args, **kwargs)[source]¶

Initialize the VectorKLEngine.

Parameters:
  • 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.

recoverable: bool = True¶
close()[source]¶

Closes the engine.

k_encode(kl)[source]¶

Encode a BaseUKF using the VDB’s key encoder.

Return type:

str

Parameters:

kl (BaseUKF)

k_embed(encoded_kl)[source]¶

Embed an encoded BaseUKF using the VDB’s key embedder.

Return type:

List[float]

Parameters:

encoded_kl (str)

batch_k_encode(kls)[source]¶

Encode a batch of BaseUKFs using the VDB’s key encoder.

Return type:

List[str]

Parameters:

kls (Iterable[BaseUKF])

batch_k_embed(encoded_kls)[source]¶

Embed a batch of encoded BaseUKFs using the VDB’s key embedder.

Return type:

List[List[float]]

Parameters:

encoded_kls (List[str])

q_encode(query)[source]¶

Encode a query string using the VDB’s query encoder.

Return type:

str

Parameters:

query (str)

q_embed(encoded_query)[source]¶

Embed an encoded query string using the VDB’s query embedder.

Return type:

List[float]

Parameters:

encoded_query (str)

batch_q_encode(queries)[source]¶

Encode a batch of query strings using the VDB’s query encoder.

Return type:

List[str]

Parameters:

queries (Iterable[str])

batch_q_embed(encoded_queries)[source]¶

Embed a batch of encoded query strings using the VDB’s query embedder.

Return type:

List[List[float]]

Parameters:

encoded_queries (List[str])

k_encode_embed(kl)[source]¶

Encode and embed a BaseUKF using the VDB’s key encoder and embedder.

Return type:

Tuple[str, List[float]]

Parameters:

kl (BaseUKF)

batch_k_encode_embed(kls)[source]¶

Encode and embed a batch of BaseUKFs using the VDB’s key encoder and embedder.

Return type:

List[Tuple[str, List[float]]]

Parameters:

kls (Iterable[BaseUKF])

q_encode_embed(query)[source]¶

Encode and embed a query string using the VDB’s query encoder and embedder.

Return type:

Tuple[str, List[float]]

Parameters:

query (str)

batch_q_encode_embed(queries)[source]¶

Encode and embed a batch of query strings using the VDB’s query encoder and embedder.

Return type:

List[Tuple[str, List[float]]]

Parameters:

queries (Iterable[str])

property embedding_field¶

Get the vector field name used by this engine.

property adapter¶

Get the adapter used by this engine.