๐ Local Document-Powered Chatbot (FAISS + Google Gemini)A lightweight, local, knowledge-grounded chatbot that answers questions strictly based on your own documents --- powered by LangChain, FAISS, and Google Gemini.
This project implements a local Retrieval-Augmented Generation (RAG) chatbot that retrieves information from text documents stored in the knowledge_base/ directory and generates answers using Google Gemini.
LangChain --- document loading, chunking, vector stores, prompt templates
Google Gemini --- embeddings + chat model
FAISS --- fast vector similarity search
Python CLI --- simple terminal-based interaction
Document ingestion and preprocessing
Text chunking with overlap
Embedding generation using Gemini
FAISS vector indexing and similarity search
Prompt-controlled RAG generation
Retrieval evaluation with similarity scores
Responsible AI guardrails (no hallucinations)
knowledge_base/
โ
Document Loading
โ
Text Chunking (overlap)
โ
Gemini Embeddings
โ
FAISS Vector Index
โ
User Question
โ
Top-K Similarity Retrieval
โ
Prompt Template
โ
Gemini LLM Answer
Document Ingestion
All .txt files in knowledge_base/ are loaded.
Each document is wrapped in a LangChain Document object with metadata.
Text Chunking
Documents are split using RecursiveCharacterTextSplitter.
Chunking improves retrieval quality and context relevance.
Controlled via config.py:
CHUNK_SIZE
CHUNK_OVERLAP
Embedding Generation
Each chunk is converted into vectors using:
GoogleGenerativeAIEmbeddings
Embedding model is configurable.
Vector Storage
Query Processing
User question is embedded.
FAISS retrieves Top-K most relevant chunks.
Similarity scores are logged for evaluation.
Answer Generation
Retrieved chunks are injected into a custom PromptTemplate.
Gemini LLM generates an answer strictly from context.
If no relevant information exists, the system refuses safely.
This project intentionally limits model behavior to reduce hallucinations:
Answers are strictly grounded in retrieved documents.
A custom prompt enforces refusal if context is missing.
Empty or invalid user input is rejected.
Only .txt files are ingested.
Safe refusal example:
"I could not find the answer in the provided documents."
โ ๏ธ Limitations
No factual verification beyond document content.
Not suitable for medical, legal, or critical decision-making.
The system uses an explicit prompt template:
`You are a helpful assistant that answers questions strictly based on the context below.
If the answer is not contained in the context, respond with:
"I could not find the answer in the provided documents."
Context:
{context}
Question:
{question}
Answer:`
This ensures:
No hallucinations
Transparent refusal behavior
Reviewer-friendly explainability
For every user query, the system logs:
Top-K retrieved chunks
Similarity scores
Chunk source metadata
Text snippets
Example output:
[1] Source: doc_1 | Score: 0.8721 [2] Source: doc_2 | Score: 0.9345
This enables:
Manual inspection of retrieval quality
Debugging noisy or insufficient context
Clear RAG transparency
You: What is LangChain?
AI: LangChain is a framework for developing applications using language models that enables chaining prompts, retrieval, and tools.
[1] Source: doc_1 | Score: 0.8721 | Snippet: LangChain is a framework designed to simplify LLM application development... [2] Source: doc_2 | Score: 0.9345 | Snippet: FAISS is used for similarity search in vector databases...
LangChain-Docs-Bot/
โโโ main.py # CLI chatbot interface
โโโ faiss_index.py # RAG pipeline, FAISS, PromptTemplate
โโโ config.py # Chunking, embedding, retrieval config
โโโ knowledge_base/ # Local .txt documents
โ โโโ doc1.txt
โ โโโ doc2.txt
โ โโโ doc3.txt
โโโ requirements.txt
โโโ README.md
โโโ LICENSE
config.py)EMBEDDING_MODEL = "models/gemini-embedding-001" CHUNK_SIZE = 800 CHUNK_OVERLAP = 200 TOP_K = 5
+-----------------------+
| knowledge_base/ |
| (.txt documents) |
+-----------+-----------+
|
v
+-----------------------+
| Text Chunking |
| (size + overlap) |
+-----------+-----------+
|
v
+-----------------------+
| Gemini Embeddings |
+-----------+-----------+
|
v
+-----------------------+
| FAISS Index |
+-----------+-----------+
|
v
+-------------------------------+
| Top-K Similarity Retrieval |
+-----------+-------------------+
|
v
+-------------------------------+
| Prompt Template + Gemini LLM |
| (Context-grounded answer) |
+-------------------------------+
This project provides a clean, explainable, and responsible RAG implementation, suitable for:
Learning retrieval-augmented generation
Demonstrating LangChain + FAISS integration
Evaluating retrieval quality
Building local, document-grounded chatbots