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)[源代码]

基类: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.

参数:
inplace: bool = True
__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.

recoverable: bool = True
close()[源代码]

Closes the engine.

k_encode(kl)[源代码]

Encode a BaseUKF using the VDB's key encoder.

返回类型:

str

参数:

kl (BaseUKF)

k_embed(encoded_kl)[源代码]

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

返回类型:

List[float]

参数:

encoded_kl (str)

batch_k_encode(kls)[源代码]

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

返回类型:

List[str]

参数:

kls (Iterable[BaseUKF])

batch_k_embed(encoded_kls)[源代码]

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

返回类型:

List[List[float]]

参数:

encoded_kls (List[str])

q_encode(query)[源代码]

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

返回类型:

str

参数:

query (str)

q_embed(encoded_query)[源代码]

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

返回类型:

List[float]

参数:

encoded_query (str)

batch_q_encode(queries)[源代码]

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

返回类型:

List[str]

参数:

queries (Iterable[str])

batch_q_embed(encoded_queries)[源代码]

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

返回类型:

List[List[float]]

参数:

encoded_queries (List[str])

k_encode_embed(kl)[源代码]

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

返回类型:

Tuple[str, List[float]]

参数:

kl (BaseUKF)

batch_k_encode_embed(kls)[源代码]

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

返回类型:

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

参数:

kls (Iterable[BaseUKF])

q_encode_embed(query)[源代码]

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

返回类型:

Tuple[str, List[float]]

参数:

query (str)

batch_q_encode_embed(queries)[源代码]

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

返回类型:

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

参数:

queries (Iterable[str])

property embedding_field

Get the vector field name used by this engine.

property adapter

Get the adapter used by this engine.