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.Faiss documentation. You’ll need to install
langchain-community
with pip install -qU langchain-community
to use this integration
This notebook shows how to use functionality related to the FAISS
vector database using asyncio
.
LangChain implemented the synchronous and asynchronous vector store functions.
See synchronous
version here.
similarity_search_with_score
, which allows you to return not only the documents but also the distance score of the query to them. The returned distance score is L2 distance. Therefore, a lower score is better.
similarity_search_by_vector
which accepts an embedding vector as a parameter instead of a string.
k
and then filtering them. You can filter the documents based on metadata. You can also set the fetch_k
parameter when calling any search method to set how many documents you want to fetch before filtering. Here is a small example:
page = 1
max_marginal_relevance_search
as well.
fetch_k
parameter when calling similarity_search
. Usually you would want the fetch_k
parameter >> k
parameter. This is because the fetch_k
parameter is the number of documents that will be fetched before filtering. If you set fetch_k
to a low number, you might not get enough documents to filter from.
$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)