A learning project demonstrating how to build a tool-enabled AI agent backend using FastAPI, PostgreSQL (pgvector), and Retrieval-Augmented Generation (RAG).
The system combines LLM reasoning, tool execution, vector search, and document-based question answering into a single backend service.
This project was built as a hands-on exploration of modern AI backend architecture, focusing on agent orchestration, tool usage, and semantic retrieval.
This project shows how to build an agentic AI backend system with the following capabilities:
- LLM-based chat responses
- Automatic tool selection and execution
- Vector-based semantic search
- Retrieval-Augmented Generation (RAG)
- Multi-step agent reasoning
- Document ingestion with chunking and embeddings
- Containerized deployment using Docker
The goal of the project is to understand how modern AI applications combine LLMs, tools, and vector databases.
A basic chat endpoint powered by an OpenAI-compatible LLM API.
Endpoint:
POST /chat
The system includes an AI agent that can automatically choose and execute tools.
Implemented tools include:
- GC content calculation for DNA sequences
- Reverse complement generation
- HGVS variant parsing
Tools are registered dynamically and validated using Pydantic schemas.
Endpoint:
POST /agent/chat
Example request:
{
"message": "ATGC ka GC content batao"
}
An orchestration layer called Agent Brain decides how to handle each user request.
Routing logic:
User Query
↓
Agent Brain
↓
Tool Route | Memory Route | Chat Route
Depending on the query, the system can:
- execute a tool
- search vector memory
- answer directly using the LLM
The system supports multi-step agent workflows, where the agent can combine memory retrieval and tool execution.
Example flow:
User Query
↓
Agent Brain
↓
Memory Search (RAG)
↓
Extract Relevant Context
↓
Execute Tool (if needed)
↓
Return Final Answer
User request:
What does BRCA1 do?
Steps performed by the system:
- Agent Brain routes the query to memory search
- Vector database retrieves relevant document chunks
- Retrieved context is sent to the LLM
- LLM generates the final answer
User request:
Calculate GC content of sequence ATGCGCGTAA
Steps performed:
- Agent Brain detects a DNA sequence request
- Query is routed to the tool agent
- The
gc_contenttool is executed - The result is returned to the user
User request:
Use BRCA1 DNA sequence and calculate GC content
Steps performed:
- Agent Brain retrieves BRCA1 related data from memory
- Relevant sequence is extracted from retrieved context
- Agent calls the
gc_contenttool - Final result is returned
This demonstrates multi-step reasoning combining RAG and tool execution.
The project implements a RAG pipeline.
Documents are:
- split into chunks
- converted into embeddings
- stored in PostgreSQL using pgvector
- retrieved using semantic similarity search
Features implemented:
- document chunking
- vector embedding storage
- semantic similarity search
- similarity threshold filtering
- optional metadata filtering
Embeddings are stored in:
PostgreSQL + pgvector
This allows efficient vector similarity search directly inside the database.
The system supports ingestion of long documents with automatic chunking.
Endpoint:
POST /memory/ingest-doc
Options:
- chunk_size
- overlap
This enables indexing larger documents for semantic search.
- Python
- FastAPI
- Pydantic
- OpenAI compatible LLM APIs
- Sentence Transformers embeddings
- PostgreSQL
- pgvector
- Docker
- Docker Compose
- Pytest
app/
├── api/ # API routes
├── core/ # Configuration and settings
├── db/ # Database models and session
├── schemas/ # Pydantic schemas
├── services/ # Agent logic, embeddings, RAG pipeline
└── tools/ # Tool implementations
git clone <repo-url>
cd agentic-rag-engine
docker compose up --build
This starts:
- FastAPI application
- PostgreSQL with pgvector
http://127.0.0.1:8000/docs
You can test all endpoints from the Swagger UI.
POST /agent/chat
Example:
{
"message": "ATGC ka GC content batao"
}
POST /memory/ingest
Example:
{
"text": "BRCA1 is a tumor suppressor gene involved in DNA repair",
"source": "notes"
}
POST /agent/ask-docs
Example:
{
"question": "What does BRCA1 do?"
}
This project was created to explore:
- LLM agent orchestration
- tool-enabled AI systems
- vector search with pgvector
- Retrieval-Augmented Generation (RAG)
- AI backend architecture with FastAPI
It serves as a learning and portfolio project demonstrating how modern AI applications are built.
MIT