Skip to main content
Facebook AI Similarity Search (FAISS) is a library for efficient similarity search and clustering of dense vectors. It contains algorithms that search in sets of vectors of any size, up to ones that possibly do not fit in RAM. It also includes supporting code for evaluation and parameter tuning. See The FAISS Library paper.
You can find the FAISS documentation at this page. This notebook shows how to use functionality related to the FAISS vector database. It will show functionality specific to this integration. After going through, it may be useful to explore relevant use-case pages to learn how to use this vectorstore as part of a larger chain.

Setup

The integration lives in the langchain-community package. We also need to install the faiss package itself. We can install these with: Note that you can also install faiss-gpu if you want to use the GPU enabled version
If you want to get best in-class automated tracing of your model calls you can also set your LangSmith API key by uncommenting below:

Initialization

Manage vector store

Add items to vector store

Delete items from vector store

Query vector store

Once your vector store has been created and the relevant documents have been added you will most likely wish to query it during the running of your chain or agent.

Query directly

Performing a simple similarity search with filtering on metadata can be done as follows:
Some MongoDB query and projection operators are supported for more advanced metadata filtering. The current list of supported operators are as follows:
  • $eq (equals)
  • $neq (not equals)
  • $gt (greater than)
  • $lt (less than)
  • $gte (greater than or equal)
  • $lte (less than or equal)
  • $in (membership in list)
  • $nin (not in list)
  • $and (all conditions must match)
  • $or (any condition must match)
  • $not (negation of condition)
Performing the same above similarity search with advanced metadata filtering can be done as follows:

Similarity search with score

You can also search with score:

Other search methods

There are a variety of other ways to search a FAISS vector store. For a complete list of those methods, please refer to the API Reference

Query by turning into retriever

You can also transform the vector store into a retriever for easier usage in your chains.

Usage for retrieval-augmented generation

For guides on how to use this vector store for retrieval-augmented generation (RAG), see the following sections:

Saving and loading

You can also save and load a FAISS index. This is useful so you don’t have to recreate it everytime you use it.

Merging

You can also merge two FAISS vectorstores

API reference

For detailed documentation of all FAISS vector store features and configurations head to the API reference: python.langchain.com/api_reference/community/vectorstores/langchain_community.vectorstores.faiss.FAISS.html
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.