Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

Agentic RAG Engine

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.


What This Project Demonstrates

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.


Key Features

1. LLM Chat

A basic chat endpoint powered by an OpenAI-compatible LLM API.

Endpoint:

POST /chat

2. Tool-Based AI Agent

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"
}

3. Agent Brain (Query Orchestration)

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

4. Multi-Step Agent Reasoning

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

Example 1 — Document Question (RAG)

User request:

What does BRCA1 do?

Steps performed by the system:

  1. Agent Brain routes the query to memory search
  2. Vector database retrieves relevant document chunks
  3. Retrieved context is sent to the LLM
  4. LLM generates the final answer

Example 2 — Tool Execution

User request:

Calculate GC content of sequence ATGCGCGTAA

Steps performed:

  1. Agent Brain detects a DNA sequence request
  2. Query is routed to the tool agent
  3. The gc_content tool is executed
  4. The result is returned to the user

Example 3 — Multi-Step Workflow

User request:

Use BRCA1 DNA sequence and calculate GC content

Steps performed:

  1. Agent Brain retrieves BRCA1 related data from memory
  2. Relevant sequence is extracted from retrieved context
  3. Agent calls the gc_content tool
  4. Final result is returned

This demonstrates multi-step reasoning combining RAG and tool execution.


5. Retrieval-Augmented Generation (RAG)

The project implements a RAG pipeline.

Documents are:

  1. split into chunks
  2. converted into embeddings
  3. stored in PostgreSQL using pgvector
  4. retrieved using semantic similarity search

Features implemented:

  • document chunking
  • vector embedding storage
  • semantic similarity search
  • similarity threshold filtering
  • optional metadata filtering

6. Vector Database

Embeddings are stored in:

PostgreSQL + pgvector

This allows efficient vector similarity search directly inside the database.


7. Document Ingestion

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.


Tech Stack

Backend

  • Python
  • FastAPI
  • Pydantic

AI

  • OpenAI compatible LLM APIs
  • Sentence Transformers embeddings

Database

  • PostgreSQL
  • pgvector

Infrastructure

  • Docker
  • Docker Compose

Testing

  • Pytest

Project Structure

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

Running the Project

1 Clone the repository

git clone <repo-url>
cd agentic-rag-engine

2 Start services using Docker

docker compose up --build

This starts:

  • FastAPI application
  • PostgreSQL with pgvector

3 Open API documentation

http://127.0.0.1:8000/docs

You can test all endpoints from the Swagger UI.


Example API Usage

Tool Agent

POST /agent/chat

Example:

{
  "message": "ATGC ka GC content batao"
}

Document Ingestion

POST /memory/ingest

Example:

{
  "text": "BRCA1 is a tumor suppressor gene involved in DNA repair",
  "source": "notes"
}

RAG Question Answering

POST /agent/ask-docs

Example:

{
  "question": "What does BRCA1 do?"
}

Learning Goals

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.


License

MIT

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages