ahvn.utils.vdb.base module¶

class ahvn.utils.vdb.base.VectorDatabase(collection=None, provider=None, encoder=None, embedder=None, connect=False, **kwargs)[source]¶

Bases: object

Parameters:
  • collection (Optional[str])

  • provider (Optional[str])

  • encoder (Union[Callable[[Any], str], Tuple[Callable[[Any], str], Callable[[Any], str]]])

  • embedder (Optional[Union[Callable[[str], List[float]], Tuple[Callable[[str], List[float]], Callable[[str], List[float]]], 'LLM']])

  • connect (bool)

__init__(collection=None, provider=None, encoder=None, embedder=None, connect=False, **kwargs)[source]¶
Parameters:
connect()[source]¶

Create the appropriate vector store based on provider.

Return type:

VectorStore

Returns:

LlamaIndex VectorStore instance.

close()[source]¶
k_encode(kl)[source]¶
Return type:

str

Parameters:

kl (Any)

k_embed(encoded_kl)[source]¶
Return type:

List[float]

Parameters:

encoded_kl (str)

batch_k_encode(kls)[source]¶
Return type:

List[str]

Parameters:

kls (Iterable[Any])

batch_k_embed(encoded_kls)[source]¶
Return type:

List[List[float]]

Parameters:

encoded_kls (List[str])

q_encode(query)[source]¶
Return type:

str

Parameters:

query (Any)

q_embed(encoded_query)[source]¶
Return type:

List[float]

Parameters:

encoded_query (str)

batch_q_encode(queries)[source]¶
Return type:

List[str]

Parameters:

queries (Iterable[str])

batch_q_embed(encoded_queries)[source]¶
Return type:

List[List[float]]

Parameters:

encoded_queries (List[str])

k_encode_embed(obj)[source]¶

Encode an object and generate its embedding.

Parameters:

obj (Any) – Object to encode and embed.

Return type:

Tuple[str, List[float]]

Returns:

Tuple of (encoded_text, embedding).

batch_k_encode_embed(objs)[source]¶

Encode a batch of objects and generate their embeddings.

Parameters:

objs (Iterable[Any]) – Iterable of objects to encode and embed.

Return type:

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

Returns:

List of tuples of (encoded_text, embedding).

q_encode_embed(query)[source]¶

Encode a query and generate its embedding.

Parameters:

query (Any) – Query to encode and embed.

Return type:

Tuple[str, List[float]]

Returns:

Tuple of (encoded_text, embedding).

batch_q_encode_embed(queries)[source]¶

Encode a batch of queries and generate their embeddings.

Parameters:

queries (Iterable[Any]) – Iterable of queries to encode and embed.

Return type:

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

Returns:

List of tuples of (encoded_text, embedding).

search(query=None, embedding=None, topk=5, filters=None, *args, **kwargs)[source]¶
insert(record)[source]¶

Insert a single record into the vector database.

Parameters:

record (Dict[str, Any]) – Dictionary containing the record data with vector and text fields.

Return type:

None

delete(record_id)[source]¶

Delete a record from the vector database by ID.

Parameters:

record_id (Union[str, int]) – ID of the record to delete.

Return type:

None

batch_insert(records)[source]¶

Insert multiple records into the vector database.

Parameters:

records (List[Dict[str, Any]]) – List of dictionaries containing record data.

Return type:

None

clear()[source]¶

Clear all records from the vector database.

Return type:

None

flush()[source]¶

Flush any pending operations to the vector database.

Return type:

None