FAISS (Facebook AI Similarity Search) is a library for fast vector search and clustering on CPUs or GPUs. In a question-answering application, it can index document embeddings so a query can retrieve similar content. It is presented as capable of handling billions of vectors. section 7.5.1 section 10.3.3
A vector index organizes embeddings to make similarity searches efficient. Index choices involve trade-offs among search speed, accuracy, and memory use; FAISS supports different vector comparisons and index types. The PDF workflow uses FAISS through LangChain rather than configuring those choices directly. section 7.5.1 section 10.3.3
Index PDFs for question answering
Load the PDFs, split their text into chunks, create OpenAI embeddings, and build the index with `FAISS.from_documents(chunks, embeddings)`. The illustrated splitter uses 2,048-character chunks with 200 characters of overlap. The PDFs contain confidential business data, so this illustrative indexing call should not be mistaken for a complete deployment plan. section 10.3.3
Listing 10.4 Q&A over my PDFs using LangChain
from langchain_community.vector stores import FAISS
from langchain_community.docstore.document import Document
from langchain.chains.question_answering import load_qa_chain
from langchain.text_splitter import CharacterTextSplitter
...
def create_index():
# load the documents and create the index
docs = load_pdfs()
text_splitter = CharacterTextSplitter(
separator="\n",
chunk_size=2048,
chunk_overlap=200,
length_function=len
)
# Convert the chunks of text into embeddings
print("Chunking and creating embeddings...")
chunks = text_splitter.split_documents(docs)
embeddings = OpenAIEmbeddings(openai_api_key=OPENAI_KEY)
vectordb = FAISS.from_documents(chunks, embeddings)
return vectordb
def main():
vectordb = create_index()
llm = OpenAI(openai_api_key=OPENAI_KEY)
chain = load_qa_chain(llm, chain_type='stuff')
while True:
prompt = check_prompt(input(
'Ask a question against the PDF (type "quit" to exit):'))
docs = vectordb.similarity_search(prompt, k=3, fetch_k=10)
response = chain.invoke({'input_documents': docs,
'question': prompt},
return_only_outputs=True)
print(f"Answer:\n {response['output_text']}")
if __name__ == "__main__":
main()
The LangChain listing shows the PDF-loading, chunking, embedding, and FAISS index-creation steps together. section 10.3.3



