Retrieve Documents from Faiss Index
LlamaIndex reader that retrieves documents from an existing in-memory Faiss index using vector similarity search for downstream data processing.
Why it matters
Integrate your existing Faiss vector index with LlamaIndex to retrieve relevant documents for downstream data structuring and analysis.
Outcomes
What it gets done
Load documents from a Faiss index using a query vector.
Map document IDs to their corresponding text content.
Retrieve the k-nearest neighbors from the Faiss index.
Optionally return retrieved documents as separate entities.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/li-reader-readers-faiss | bash Overview
LlamaIndex Readers Integration: Faiss
Faiss Reader retrieves documents from an existing in-memory Faiss index using vector similarity search. It accepts query vectors, performs k-nearest neighbor lookups, and returns LlamaIndex document objects mapped from the retrieved IDs. Use this reader when you have an existing, populated Faiss index and need to retrieve documents via vector similarity queries for LlamaIndex workflows.
What it does
Faiss Reader retrieves documents through an existing in-memory Faiss index and loads them into LlamaIndex data structures. It accepts query vectors and performs k-nearest neighbor searches to fetch documents mapped to text content.
When to use - and when NOT to
Use Faiss Reader when you already have a populated Faiss index in memory and need to retrieve documents based on vector similarity queries to feed into LlamaIndex workflows.
Do NOT use Faiss Reader if you need to build, organize, insert documents into, or perform queries directly on a Faiss index - use VectorStoreIndex with FaissVectorStore instead. This reader assumes your Faiss index already exists and is populated; it only retrieves from it.
Inputs and outputs
You provide an existing Faiss Index object, a 2D numpy array of query vectors, a mapping dictionary from IDs to text strings, the number of nearest neighbors (k) to retrieve, and a flag for whether to return separate documents. The reader returns LlamaIndex document objects containing the retrieved text content from your k-nearest neighbor search results.
Installation and usage
Install via pip:
pip install llama-index-readers-faiss
Basic usage pattern:
from llama_index.readers.faiss import FaissReader
# Initialize FaissReader with an existing Faiss Index object
reader = FaissReader(index="<Faiss Index Object>")
# Load data from Faiss
documents = reader.load_data(
query="<Query Vector>", # 2D numpy array of query vectors
id_to_text_map={"<ID>": "<Text>"}, # A map from IDs to text
k=4, # Number of nearest neighbors to retrieve
separate_documents=True, # Whether to return separate documents
)
Integrations
This loader is designed to be used as a way to load data into LlamaIndex.
Who it's for
Data engineers and ML practitioners who maintain Faiss indexes for vector similarity search and need to pipe retrieval results into LlamaIndex for RAG applications, question answering, or document processing workflows.
Source README
LlamaIndex Readers Integration: Faiss
Overview
Faiss Reader retrieves documents through an existing in-memory Faiss index. These documents can then be used in a downstream LlamaIndex data structure. If you wish to use Faiss itself as an index to organize documents, insert documents, and perform queries on them, please use VectorStoreIndex with FaissVectorStore.
Installation
You can install Faiss Reader via pip:
pip install llama-index-readers-faiss
Usage
from llama_index.readers.faiss import FaissReader
### Initialize FaissReader with an existing Faiss Index object
reader = FaissReader(index="<Faiss Index Object>")
### Load data from Faiss
documents = reader.load_data(
query="<Query Vector>", # 2D numpy array of query vectors
id_to_text_map={"<ID>": "<Text>"}, # A map from IDs to text
k=4, # Number of nearest neighbors to retrieve
separate_documents=True, # Whether to return separate documents
)
This loader is designed to be used as a way to load data into
LlamaIndex.
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.