Vector Store Module

The rakam_systems.vector_store module defines the VectorStores class, which is responsible for managing vector stores, storing data, and handling embeddings using FAISS and SentenceTransformers.

Classes

rakam_systems.vector_store.VectorStores(...)

A class for managing multiple vector stores using FAISS and SentenceTransformers.

VectorStores

class rakam_systems.vector_store.VectorStores(base_index_path: str, embedding_model: str)

Bases: object

A class for managing multiple vector stores using FAISS and SentenceTransformers.

A class for managing vector stores with FAISS and SentenceTransformers.

create_from_files(stores_files: Dict[str, List[VSFile]]) None

Creates FAISS indexes from dictionaries of store names and VSFile objects.

Parameters:

stores_files – Dictionary where keys are store names and values are lists of VSFile objects.

create_from_nodes(store_name: str, nodes: List[Any]) None

Creates a FAISS index from a list of nodes and stores it under the given store name.

Parameters:
  • store_name – Name of the store to create.

  • nodes – List of nodes containing the content and metadata.

get_embeddings(sentences: List[str], parallel: bool = True) ndarray

Generates embeddings for a list of sentences.

Parameters:
  • sentences – List of sentences to encode.

  • parallel – Whether to use parallel processing (default is True).

Returns:

Embedding vectors for the sentences.

load_all_stores() None

Loads all vector stores from the base directory.

load_store(store_path: str) Dict[str, Any]

Loads a single vector store from the specified directory.

Parameters:

store_path – Path to the store directory.

Returns:

Dictionary containing the store’s index, nodes, and metadata.

predict_embeddings(query: str) ndarray

Predicts embeddings for a given query using the embedding model.

Parameters:

query – Query string to encode.

Returns:

Embedding vector for the query.

search(store_name: str, query: str, distance_type='cosine', number=5) dict

Searches the specified store for the closest embeddings to the query.

Parameters:
  • store_name – Name of the store to search in.

  • query – Query string to search for.

  • distance_type – Distance metric to use (default is “cosine”).

  • number – Number of closest embeddings to return.

Returns:

Dictionary of search results with suggestion texts and distances.

Methods:

  • __init__: Initializes the vector store with a base path and embedding model.

  • load_all_stores: Loads all vector stores from a directory.

  • load_store: Loads a specific vector store from a directory.

  • predict_embeddings: Generates embeddings for a given query.

  • search: Searches for the closest embeddings in the specified store.

  • get_embeddings: Generates embeddings for a list of sentences.

  • create_from_files: Creates a FAISS index from files.

  • create_from_nodes: Creates a FAISS index from nodes.

  • add_nodes: Adds nodes to an existing store and updates the index.

  • delete_nodes: Deletes nodes from an existing store.

  • add_files: Adds files and their nodes to a vector store.

  • delete_files: Deletes files and their nodes from a vector store.