class VectorStore:
Constructors: VectorStore.from_bytes(raw)
, VectorStore(documents)
A class for storing and querying document embeddings using FAISS and SentenceTransformer.
Class Method | from |
Deserializes a VectorStore from bytes. |
Method | __init__ |
Initializes the VectorStore with optional documents. |
Method | query |
Query the vector store for the most similar document chunks. |
Instance Variable | documents |
Undocumented |
Instance Variable | ids |
Undocumented |
Instance Variable | metadatas |
Undocumented |
Instance Variable | model |
Undocumented |
Instance Variable | store |
Undocumented |
Property | as |
Serializes the vector store to bytes. |
Property | metas |
Returns a JSON string of ids, metas, and documents. |
Method | _setup |
Splits documents into chunks of maximum 1000 characters. |
Deserializes a VectorStore from bytes. Args: raw (bytes): Serialized vector store. Returns: VectorStore: The deserialized instance.
Initializes the VectorStore with optional documents. Args: documents (list[dict[str, str]], optional): List of documents with 'title' and 'content'.
Query the vector store for the most similar document chunks. Args: query (str): The query string. Returns: list[dict]: List of results with document, metadata, and distance. Raises: ValueError: If the vector store is not initialized. RuntimeError: If the query fails.
list[ dict[ str, str]]
) -> tuple[ faiss.IndexFlatL2, list[ str], list[ str], list[ dict[ str, str]]]
:
¶
Splits documents into chunks of maximum 1000 characters. For each chunk: create a unique ID string made of the document title and chunk index, and a metadata dict with the document title. Creates a FAISS index for the embeddings. Args: documents (list[dict[str, str]]): List of documents. Returns: tuple: (FAISS index, list of chunks, list of ids, list of metas)