Skip to content

API Reference parrot.stores.faiss_store

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.stores.faiss_store

View source

FAISSStore: In-memory Vector Store implementation using FAISS.

Provides high-performance vector similarity search with:

  • In-memory vector storage with FAISS indexes
  • Multiple distance metrics (Cosine, L2, Inner Product)
  • CPU-only execution (GPU support removed)
  • MMR (Maximal Marginal Relevance) search
  • Metadata filtering
  • Collection management
  • Async context manager support

Alias AbstractStore

Re-exported from parrot.stores.abstract.AbstractStore.

Alias DistanceStrategy

Re-exported from parrot.stores.models.DistanceStrategy.

Alias Document

Re-exported from parrot.stores.models.Document.

Class FAISSStore

An in-memory FAISS vector store implementation, completely independent of Langchain.

This store provides high-performance vector similarity search using FAISS indexes with support for multiple distance metrics and metadata filtering.

Features:

  • Multiple FAISS index types (Flat, IVF, HNSW)
  • CPU-only execution
  • Cosine, L2, and Inner Product distance metrics
  • MMR (Maximal Marginal Relevance) search
  • Metadata filtering
  • Persistent storage via save/load
Parameter Type Default Description
collection_name str 'default' Name of the collection/index
id_column str 'id' Name of the ID column
embedding_column str 'embedding' Name of the embedding column
document_column str 'document' Name of the document content column
text_column str 'text' Name of the text column
metadata_column str 'metadata' Name of the metadata column
embedding_model Union[dict, str] 'sentence-transformers/all-mpnet-base-v2' Embedding model configuration (dict or string)
embedding Optional[Callable] None Custom embedding function
distance_strategy DistanceStrategy DistanceStrategy.COSINE Distance metric to use (COSINE, EUCLIDEAN_DISTANCE, etc.)
index_type str 'Flat' Type of FAISS index ("Flat", "IVF", "HNSW")
nlist int 100 Number of clusters for IVF indexes
nprobe int 10 Number of clusters to probe for IVF search
m int 32 Number of connections per layer for HNSW
ef_construction int 40 Size of dynamic candidate list for HNSW construction
ef_search int 16 Size of dynamic candidate list for HNSW search
**kwargs {}

Method FAISSStore.define_collection_table

Define an in-memory collection table for saving vector + metadata information.

This method is compatible with the PgVectorStore pattern but operates in-memory.

define_collection_table(collection_name: str, dimension: int = 384, **kwargs) -> Dict[str, Any]

Parameter Type Default Description
collection_name str Name of the collection
dimension int 384 Dimension of the embedding vectors
**kwargs {} Additional arguments (for compatibility)

Returns: Dict[str, Any] — Dictionary representing the collection structure

Method FAISSStore.connection

Establish connection (for compatibility with AbstractStore).

Since FAISS is in-memory, this just marks the store as connected.

connection() -> bool

Returns: bool — True if successful

Method FAISSStore.disconnect

Disconnect and cleanup resources.

Clears all in-memory data.

disconnect() -> None

Method FAISSStore.prepare_embedding_table

Prepare the embedding table/collection for storing vectors.

prepare_embedding_table(collection: str = None, dimension: int = None, **kwargs) -> bool

Parameter Type Default Description
collection str None Collection name
dimension int None Embedding dimension
**kwargs {} Additional arguments

Returns: bool — True if successful

Method FAISSStore.create_embedding_table

Create an embedding table/collection (alias for prepare_embedding_table).

create_embedding_table(collection: str = None, dimension: int = None, **kwargs) -> None

Parameter Type Default Description
collection str None Collection name
dimension int None Embedding dimension
**kwargs {} Additional arguments

Method FAISSStore.create_collection

Create a new collection.

create_collection(collection: str, **kwargs) -> None

Parameter Type Default Description
collection str Collection name
**kwargs {} Additional arguments (e.g., dimension)

Method FAISSStore.add_documents

Add documents to the FAISS store.

add_documents(documents: List[Document], collection: str = None, embedding_column: str = None, content_column: str = None, metadata_column: str = None, **kwargs) -> None

Parameter Type Default Description
documents List[Document] List of Document objects to add
collection str None Collection name (optional, uses default if not provided)
embedding_column str None Name of the embedding column (for compatibility)
content_column str None Name of the content column (for compatibility)
metadata_column str None Name of the metadata column (for compatibility)
**kwargs {} Additional arguments

Method FAISSStore.get_distance_strategy

Return the appropriate distance strategy based on the metric or configured strategy.

get_distance_strategy(query_embedding: np.ndarray, metric: str = None) -> str

Parameter Type Default Description
query_embedding np.ndarray Query embedding vector (for compatibility)
metric str None Optional metric string ('COSINE', 'L2', 'IP', 'DOT')

Returns: str — Distance strategy as string

Method FAISSStore.similarity_search

Perform similarity search with optional threshold filtering.

similarity_search(query: str, collection: str = None, k: Optional[int] = None, limit: int = None, metadata_filters: Optional[Dict[str, Any]] = None, score_threshold: Optional[float] = None, metric: str = None, embedding_column: str = None, content_column: str = None, metadata_column: str = None, id_column: str = None, **kwargs) -> List[SearchResult]

Parameter Type Default Description
query str The search query text
collection str None Collection name (optional, uses default if not provided)
k Optional[int] None Number of results to return (alias for limit)
limit int None Maximum number of results to return
metadata_filters Optional[Dict[str, Any]] None Dictionary of metadata filters to apply
score_threshold Optional[float] None Minimum score threshold (results below threshold filtered out)
metric str None Distance metric to use ('COSINE', 'L2', 'IP')
embedding_column str None Name of the embedding column (for compatibility)
content_column str None Name of the content column (for compatibility)
metadata_column str None Name of the metadata column (for compatibility)
id_column str None Name of the ID column (for compatibility)
**kwargs {} Additional arguments

Returns: List[SearchResult] — List of SearchResult objects with content, metadata, score, and id

Method FAISSStore.asearch

Async alias for :meth:similarity_search to match store interface expectations.

asearch(query: str, collection: Optional[str] = None, k: Optional[int] = None, limit: Optional[int] = None, metadata_filters: Optional[Dict[str, Any]] = None, score_threshold: Optional[float] = None, metric: Optional[str] = None, embedding_column: Optional[str] = None, content_column: Optional[str] = None, metadata_column: Optional[str] = None, id_column: Optional[str] = None, **kwargs) -> List[SearchResult]

Parameter Type Default Description
query str
collection Optional[str] None
k Optional[int] None
limit Optional[int] None
metadata_filters Optional[Dict[str, Any]] None
score_threshold Optional[float] None
metric Optional[str] None
embedding_column Optional[str] None
content_column Optional[str] None
metadata_column Optional[str] None
id_column Optional[str] None
**kwargs {}

Returns: List[SearchResult]

Method FAISSStore.mmr_search

Perform MMR (Maximal Marginal Relevance) search for diversity.

MMR balances relevance with diversity by selecting documents that are:

  1. Relevant to the query
  2. Diverse from already selected documents

mmr_search(query: str, collection: str = None, k: int = 4, fetch_k: Optional[int] = None, lambda_mult: float = 0.5, metadata_filters: Optional[Dict[str, Any]] = None, score_threshold: Optional[float] = None, metric: str = None, embedding_column: str = None, content_column: str = None, metadata_column: str = None, id_column: str = None, **kwargs) -> List[SearchResult]

Parameter Type Default Description
query str The search query text
collection str None Collection name (optional, uses default if not provided)
k int 4 Number of results to return
fetch_k Optional[int] None Number of candidates to fetch (default: k*3)
lambda_mult float 0.5 Diversity parameter (0-1) - 1.0 = maximum relevance (no diversity) - 0.0 = maximum diversity (no relevance)
metadata_filters Optional[Dict[str, Any]] None Dictionary of metadata filters to apply
score_threshold Optional[float] None Minimum score threshold
metric str None Distance metric to use ('COSINE', 'L2', 'IP')
embedding_column str None Name of the embedding column (for compatibility)
content_column str None Name of the content column (for compatibility)
metadata_column str None Name of the metadata column (for compatibility)
id_column str None Name of the ID column (for compatibility)
**kwargs {} Additional arguments

Returns: List[SearchResult] — List of SearchResult objects ordered by MMR score

Method FAISSStore.get_vector

Get the FAISS vector store (for compatibility).

get_vector(metric_type: str = None, **kwargs)

Parameter Type Default Description
metric_type str None Distance metric type
**kwargs {} Additional arguments

Method FAISSStore.from_documents

Create Vector Store from Documents.

from_documents(documents: List[Document], collection: Union[str, None] = None, **kwargs) -> FAISSStore

Parameter Type Default Description
documents List[Document] List of Documents
collection Union[str, None] None Collection Name
**kwargs {} Additional Arguments

Returns: FAISSStore — The FAISSStore instance

Method FAISSStore.save

Save the FAISS store to disk.

save(file_path: Union[str, Path]) -> None

Parameter Type Default Description
file_path Union[str, Path] Path to save the store

Method FAISSStore.load

Load the FAISS store from disk.

load(file_path: Union[str, Path]) -> None

Parameter Type Default Description
file_path Union[str, Path] Path to load the store from

Method FAISSStore.delete_documents

Delete documents by their IDs from the FAISS store.

delete_documents(document_ids: List[str], collection: str = None, **kwargs) -> None

Parameter Type Default Description
document_ids List[str] List of document IDs to delete
collection str None Collection name (optional, uses default if not provided)
**kwargs {} Additional arguments

Method FAISSStore.delete_documents_by_filter

Delete documents that match a filter function from the FAISS store.

delete_documents_by_filter(filter_func, collection: str = None, **kwargs) -> None

Parameter Type Default Description
filter_func A function that takes metadata and returns True if the document should be deleted
collection str None Collection name (optional, uses default if not provided)
**kwargs {} Additional arguments

Method FAISSStore.dump_to_s3

Serialize the FAISS index to a temp file and upload to S3.

The store is saved using the existing :meth:save method (pickle + per-collection .index files), then bundled into a tarball and uploaded via file_manager.upload_file.

dump_to_s3(key: str, file_manager) -> str

Parameter Type Default Description
key str S3 object key prefix (e.g. a chatbot_id string). The actual filename will be {key}.faiss.
file_manager A FileManagerToolkit instance exposing upload_file(source_path, destination, destination_name).

Returns: str — The S3 path string returned by upload_file (result["path"]).

Method FAISSStore.load_from_s3

Download a FAISS store tarball from S3 and hydrate a new instance.

load_from_s3(key: str, file_manager, **kwargs) -> FAISSStore

Parameter Type Default Description
key str S3 object path returned by :meth:dump_to_s3.
file_manager A FileManagerToolkit instance exposing download_file(path, destination).
**kwargs {} Keyword arguments forwarded to :class:FAISSStore.__init__.

Returns: FAISSStore — A hydrated :class:FAISSStore instance.

Attribute FAISS_AVAILABLE

Attribute FaissStore

Alias SearchResult

Re-exported from parrot.stores.models.SearchResult.

Alias quiet_faiss_loader

Re-exported from parrot.utils.faiss_logging.quiet_faiss_loader.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally