Skip to main content

Faiss

Langchain vector store for FAISS. Supports save/load to disk.

Install

pip install langchain-faiss-vectorstore

or

uv add langchain-faiss-vectorstore

API Reference

__init__

def __init__(
    self,
    embedding_function: Embeddings | None = None,
    index: faiss.Index | None = None,
    **kwargs,
)
Parameter Type Description
embedding_function Embeddings | None Embedding function used to embed queries and texts (e.g., FastEmbedEmbeddings).
index faiss.Index | None Optional pre-built FAISS index. If None, creates an IndexIDMap wrapping IndexFlatL2 with dimension 0 (auto-sized on first add_texts).

from_texts

def from_texts(
    cls,
    texts: list[str],
    embedding: Embeddings | None = None,
    metadatas: list[dict] | None = None,
    ids: list[str] | None = None,
    **kwargs,
) -> Faiss
Parameter Type Description
texts list[str] Texts to index.
embedding Embeddings | None Embedding function.
metadatas list[dict] | None Optional metadata dicts, one per text.
ids list[str] | None Optional document IDs. Auto-generated if not provided.

Returns: Faiss — a new vector store with the texts indexed.


add_texts

def add_texts(
    self,
    texts: list[str],
    metadatas: list[dict] | None = None,
    ids: list[str] | None = None,
    **kwargs,
) -> list[str]
Parameter Type Description
texts list[str] Texts to add to the index.
metadatas list[dict] | None Optional metadata dicts, one per text. Defaults to {}.
ids list[str] | None Optional document IDs. Auto-generated if not provided.

Returns: list[str] — the IDs of the added texts.


delete

def delete(
    self,
    ids: list[str] | None = None,
    **kwargs,
) -> bool | None
Parameter Type Description
ids list[str] | None List of document IDs to remove.

Returns: boolTrue if deletion succeeded. Raises ValueError if ids is None.


similarity_search

def similarity_search(
    self,
    query: str,
    k: int = 4,
    **kwargs,
) -> list[Document]
Parameter Type Description
query str Query text.
k int Number of documents to return. Default 4.

Returns: list[Document] — documents most similar to the query, ordered by L2 distance (ascending).


similarity_search_with_score

def similarity_search_with_score(
    self,
    query: str,
    k: int = 4,
    **kwargs,
) -> list[tuple[Document, float]]
Parameter Type Description
query str Query text.
k int Number of documents to return. Default 4.

Returns: list[tuple[Document, float]] — tuples of (Document, L2_distance). Lower distance = more similar.


save_local

def save_local(
    self,
    folder_path: str | Path,
) -> None
Parameter Type Description
folder_path str | Path Directory to save the index and document data. Created if it doesn't exist.

Writes two files into folder_path:

  • index.faiss — the serialized FAISS index.
  • docs.json — document contents and metadata.

load_local

def load_local(
    cls,
    folder_path: str | Path,
    embedding_function: Embeddings,
    allow_dangerous_deserialization: bool = False,
) -> Faiss
Parameter Type Description
folder_path str | Path Directory containing index.faiss and docs.json.
embedding_function Embeddings Embedding function to use for future queries.
allow_dangerous_deserialization bool Safety flag (acknowledged). Default False.

Returns: Faiss — a restored vector store instance.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_faiss_vectorstore-0.1.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_faiss_vectorstore-0.1.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file langchain_faiss_vectorstore-0.1.0.tar.gz.

File metadata

File hashes

Hashes for langchain_faiss_vectorstore-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bcf36cfd2de88038b5e8e22353f0f84ad2f633f7553f0434829f99279fbf1876
MD5 1c32c1824e69c8ebe8fd726db1385dba
BLAKE2b-256 e8ba0f4a68844f9dab7e3d5c8f2a84dbaad00f4a35232f0d8cfedc4c58f43434

See more details on using hashes here.

File details

Details for the file langchain_faiss_vectorstore-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_faiss_vectorstore-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 75ea19ae243de06f35f586b9d2c74d917013b7b90b675eb6453a124bc2856947
MD5 e844b591be4b56ed7d43d12163f77004
BLAKE2b-256 f4767aab84a4355924ef53258624ae7a31da4fa0950457ade50762729ec17600

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page