VectorDBBlock

class VectorDBBlock(MemoryBlock):

An implementation of the :obj:MemoryBlock abstract base class for maintaining and retrieving information using vector embeddings within a vector database.

Parameters:

  • storage (Optional[BaseVectorStorage], optional): The storage mechanism for the vector database. Defaults to in-memory :obj:Qdrant if not provided. (default: :obj:None)
  • embedding (Optional[BaseEmbedding], optional): Embedding mechanism to convert chat messages into vector representations. Defaults to :obj:OpenAiEmbedding if not provided. (default: :obj:None)

init

def __init__(
    self,
    storage: Optional[BaseVectorStorage] = None,
    embedding: Optional[BaseEmbedding] = None
):

retrieve

def retrieve(self, keyword: str, limit: int = 3):

Retrieves similar records from the vector database based on the content of the keyword.

Parameters:

  • keyword (str): This string will be converted into a vector representation to query the database.
  • limit (int, optional): The maximum number of similar messages to retrieve. (default: :obj:3).

Returns:

List[ContextRecord]: A list of memory records retrieved from the vector database based on similarity to :obj:current_state.

write_records

def write_records(self, records: List[MemoryRecord]):

Converts the provided chat messages into vector representations and writes them to the vector database.

Parameters:

  • records (List[MemoryRecord]): Memory records to be added to the memory.

clear

def clear(self):

Removes all records from the vector database memory.