Document Assistant

Document Assistant

Enables natural language search and analysis of uploaded PDF, CSV, and Excel documents using retrieval-augmented generation and MCP tools, providing contextual answers to user queries.

Category
Visit Server

README

๐Ÿค– AI Document Scanner Using RAG & MCP Tools with Python

An intelligent AI Document Scanner and Assistant built with Python that allows users to upload documents, search their contents, and ask questions using Retrieval-Augmented Generation (RAG) and Model Context Protocol (MCP) tools.

The application combines document processing, text chunking, vector embeddings, FAISS similarity search, MCP tools, and Large Language Models (LLMs) to provide contextual answers from uploaded documents.


๐Ÿ“Œ Project Overview

Traditional document search often depends on exact keyword matching. This project uses semantic search through vector embeddings, allowing users to ask questions naturally.

The system:

  1. Accepts documents from the user.
  2. Extracts text from the documents.
  3. Splits the text into smaller chunks.
  4. Converts chunks into vector embeddings.
  5. Stores embeddings in a FAISS vector database.
  6. Retrieves relevant chunks when the user asks a question.
  7. Uses an LLM to generate an answer based on the retrieved context.
  8. Uses MCP tools to expose document search and analysis capabilities to an AI agent.

โœจ Features

  • ๐Ÿ“„ PDF document processing
  • ๐Ÿ“Š CSV and Excel data analysis
  • ๐Ÿ” Semantic document search
  • ๐Ÿง  Retrieval-Augmented Generation (RAG)
  • ๐Ÿ—‚๏ธ FAISS vector database
  • ๐Ÿค– LLM-powered question answering
  • ๐Ÿ”Œ Model Context Protocol (MCP) tool integration
  • ๐Ÿ’ฌ Interactive document chat
  • ๐ŸŒ Streamlit web interface
  • ๐Ÿ“‘ Document chunking and embeddings
  • ๐Ÿ”Ž Context-aware information retrieval
  • ๐Ÿงฉ Modular project architecture
  • ๐Ÿ” Environment-variable based API key configuration

๐Ÿ—๏ธ Architecture

                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚        User         โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                               โ”‚
                               โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚    Streamlit UI     โ”‚
                    โ”‚       app.py        โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                               โ”‚
                               โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚   Document Loader   โ”‚
                    โ”‚  PDF / CSV / Excel  โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                               โ”‚
                               โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚ Text Splitting &    โ”‚
                    โ”‚   Preprocessing     โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                               โ”‚
                               โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚   Embedding Model   โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                               โ”‚
                               โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚  FAISS Vector Store โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                               โ”‚
                         User Question
                               โ”‚
                               โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚ Semantic Retrieval  โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                               โ”‚
                               โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚     MCP Tools       โ”‚
                    โ”‚ PDF / CSV / Excel   โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                               โ”‚
                               โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚    RAG Pipeline     โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                               โ”‚
                               โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚        LLM          โ”‚
                    โ”‚ Gemini / Other LLM  โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                               โ”‚
                               โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚     AI Response     โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ”„ RAG Workflow

1. Document Loading

Documents are loaded using appropriate Python libraries.

  • PDF โ†’ PyPDF
  • Excel โ†’ Pandas / OpenPyXL
  • CSV โ†’ Pandas

2. Text Splitting

Large documents are divided into smaller chunks using a text splitter. This improves retrieval accuracy and keeps prompts manageable.

3. Embeddings

Each text chunk is converted into a numerical vector representing its semantic meaning.

Document Text
      |
      v
Embedding Model
      |
      v
Numerical Vector

4. Vector Storage

The generated vectors are stored in FAISS, enabling efficient similarity-based retrieval.

5. Semantic Search

When the user asks a question, the question is converted into an embedding and compared against stored document vectors. The most relevant chunks are retrieved.

6. Response Generation

The retrieved context is passed to the LLM along with the user's question. The model generates an answer based on the retrieved information.


๐Ÿ”Œ MCP Integration

The project uses Model Context Protocol (MCP) to expose document-related functionality as tools that an AI agent can call.

Example MCP Tools

search_pdf(question)
find_employee(name)
analyze_csv(question)

This allows an AI system to retrieve information from documents or analyze structured data when required.

Example MCP Workflow

User
  |
  v
"Find the details of Manoj Sarkar."
  |
  v
AI Agent
  |
  v
MCP Tool
find_employee("Manoj Sarkar")
  |
  v
Vector / Document Search
  |
  v
Relevant Information
  |
  v
LLM
  |
  v
Final Answer

๐Ÿ› ๏ธ Technologies Used

Technology Purpose
Python Core programming language
Streamlit Web application interface
LangChain RAG and document processing
FAISS Vector similarity search
MCP AI tool integration
Google Gemini Large Language Model
PyPDF PDF text extraction
Pandas Data processing
OpenPyXL Excel file processing
Vector Embeddings Semantic representation
python-dotenv Environment variable management

๐Ÿ“ Project Structure

AI-Document-Scanner/
โ”‚
โ”œโ”€โ”€ app.py
โ”œโ”€โ”€ server.py
โ”œโ”€โ”€ client.py
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ README.md
โ”‚
โ”œโ”€โ”€ assistants/
โ”‚   โ”œโ”€โ”€ pdf_assistant.py
โ”‚   โ”œโ”€โ”€ excel_assistant.py
โ”‚   โ”œโ”€โ”€ csv_assistant.py
โ”‚   โ””โ”€โ”€ docx_assistant.py
โ”‚
โ”œโ”€โ”€ utils/
โ”‚   โ”œโ”€โ”€ loaders.py
โ”‚   โ”œโ”€โ”€ splitter.py
โ”‚   โ”œโ”€โ”€ vectorstore.py
โ”‚   โ”œโ”€โ”€ rag_pipeline.py
โ”‚   โ”œโ”€โ”€ llm_provider.py
โ”‚   โ””โ”€โ”€ prompts.py
โ”‚
โ”œโ”€โ”€ mcp_tools/
โ”‚   โ”œโ”€โ”€ pdf_tool.py
โ”‚   โ”œโ”€โ”€ rag_tool.py
โ”‚   โ”œโ”€โ”€ excel_tool.py
โ”‚   โ””โ”€โ”€ csv_tool.py
โ”‚
โ”œโ”€โ”€ data/
โ”‚   โ””โ”€โ”€ sample_documents/
โ”‚
โ””โ”€โ”€ .env

The exact files and folders may vary depending on the current implementation.


โš™๏ธ Installation

1. Clone the Repository

git clone https://github.com/your-username/AI-Document-Scanner.git
cd AI-Document-Scanner

2. Create a Virtual Environment

Windows

python -m venv venv
venv\Scripts\activate

Linux/macOS

python3 -m venv venv
source venv/bin/activate

3. Install Dependencies

pip install -r requirements.txt

๐Ÿ”‘ Environment Variables

Create a .env file in the project root.

Google Gemini

GOOGLE_API_KEY=your_google_api_key

If your implementation also supports OpenAI:

OPENAI_API_KEY=your_openai_api_key

Important: Never commit your .env file or API keys to GitHub.

Add the following to .gitignore:

.env
venv/
__pycache__/
*.pyc
.faiss/

โ–ถ๏ธ Running the Application

Start the Streamlit application:

streamlit run app.py

Then open the application in your browser:

http://localhost:8501

๐Ÿ’ก Example Questions

After uploading a document, users can ask questions such as:

What is this document about?
Summarize the document.
Who is Manoj Sarkar?
Find the employee with the highest sales.
What is the total revenue?
What are the main points discussed in the document?
Find information related to a specific topic.

๐Ÿงช Example RAG Pipeline

documents = load_documents(file_path)

chunks = split_documents(documents)

vectorstore = create_vectorstore(chunks)

results = vectorstore.similarity_search(query, k=4)

context = "\n".join(
    document.page_content
    for document in results
)

response = llm.invoke(
    f"""
    Answer the question using the following context:

    {context}

    Question:
    {query}
    """
)

๐Ÿ”Œ Example MCP Tool

A simplified MCP tool can look like:

from mcp.server.fastmcp import FastMCP

mcp = FastMCP("Document Assistant")


@mcp.tool()
def search_pdf(question: str) -> str:
    """Search the uploaded PDF and return relevant information."""

    # Vector search implementation
    return "Relevant document information"

The MCP server exposes this functionality so that an AI client or agent can use it when required.


๐ŸŽฏ Use Cases

This project can be useful for:

  • ๐Ÿ“š Research document assistants
  • ๐Ÿข Company knowledge bases
  • ๐Ÿ“„ Legal document search
  • ๐ŸŽ“ Educational document analysis
  • ๐Ÿ‘จโ€๐Ÿ’ผ HR document assistants
  • ๐Ÿ“Š Business report analysis
  • ๐Ÿงพ Invoice and report processing
  • ๐Ÿ“‘ Policy and documentation search
  • ๐Ÿค– AI-powered knowledge management systems

๐Ÿš€ Future Enhancements

  • [ ] Multi-document conversational memory
  • [ ] DOCX support
  • [ ] Image document scanning
  • [ ] OCR integration
  • [ ] Voice input
  • [ ] Source/page citations
  • [ ] Chat history
  • [ ] User authentication
  • [ ] Multi-user support
  • [ ] Cloud deployment
  • [ ] Advanced agentic workflows
  • [ ] Additional MCP tools
  • [ ] Database integration
  • [ ] Document summarization
  • [ ] Hybrid keyword + semantic search
  • [ ] Reranking for improved retrieval accuracy

๐Ÿ” Security

For security:

  • Store API keys in .env.
  • Never upload API keys to GitHub.
  • Add .env to .gitignore.
  • Avoid storing sensitive documents in public repositories.
  • Validate uploaded files before processing.

๐Ÿง  Key Concepts Demonstrated

This project demonstrates practical knowledge of:

  • Python
  • Generative AI
  • Large Language Models
  • Retrieval-Augmented Generation
  • Vector Databases
  • Semantic Search
  • Embeddings
  • LangChain
  • FAISS
  • Model Context Protocol
  • AI Agents
  • Streamlit
  • Document Processing
  • API Integration

๐Ÿ‘จโ€๐Ÿ’ป Author

Manoj Sarkar

B.Tech in Computer Science & Engineering

Interested in Python, Generative AI, Agentic AI, RAG, MCP, and AI-powered applications.


โญ Support

If you find this project useful, consider giving the repository a โญ on GitHub.


๐Ÿ“„ License

This project is intended for educational and development purposes. Add an appropriate license file if you plan to distribute or reuse the project publicly.

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured