A FastAPI-based service for embedding and querying documentation (including code, text, images, PDFs) using a vector database (FAISS) and a Retrieval-Augmented Generation (RAG) agent powered by a multimodal library (CLIP).
- Ingest Git Repository: Clone any public Git repo (and optionally a branch) via
/ingest/gitand embed.txt,.md,.pdf,.png,.jpgusing CLIP. - Upload File: POST a single file to
/ingest/upload(text, PDF, image) and upsert into FAISS. - Vector Database: Persist embeddings in FAISS (
tmp/vector_store.index) with document metadata (tmp/documents.pkl). - Query API:
/query/accepts a JSON body (question,top_k) and returns a RAG-generated answer plus source list and citations. - Multimodal Embeddings: Use CLIPModel for both text and images.
- Swagger UI: Interactive API docs at
http://<host>:<port>/docs.
- Python 3.9+
- Git CLI
- (Optional) Docker & Docker Compose
- A Perplexity API Key (set
PERPLEXITY_API_KEYin.env)
- Clone this repo
git clone https://github.com/your-org/assignment.git cd assignment - Create & activate a virtual environment
python -m venv .venv source .venv/bin/activate # Linux/macOS .\.venv\Scripts\activate
- Install dependencies
pip install --upgrade pip pip install -r requirements.txt
- Setup environment variables
cp .env.example .env
Edit .env and set your PERPLEXITY_API_KEY
From project root
uvicorn app.main:app --host 0.0.0.0 --port 2000- Build
docker build -t assignment . - Run
docker run -d --name assignment -p 2000:2000 \ -e PERPLEXITY_API_KEY="<your_key>" \ assignment - Swagger UI http://localhost:2000/docs
- Ingest Git Repo
POST /ingest/git Content-Type: application/json { "repo_url": "https://github.com/your/repo.git", "branch": "main" # optional, default is default branch }
Response
{ "status": "Ingestion complete", "documents": <count> }- Upload File
POST /ingest/upload Content-Type: multipart/form-data file: <upload your .txt | .md | .pdf | .png | .jpg | .jpeg>
Response
{ "status": "Ingestion complete", "document": "<path>" }POST /query/
Content-Type: application/json
{
"question": "Your question here",
"top_k": 3 # optional, default = 3
}Response
{
"response": "<LLM answer>",
"sources": ["path/to/doc1", "path/to/doc2", ...],
"web_citations": [ ... ]
}
# .env
PERPLEXITY_API_KEY=your_perplexity_key
BASE_DIR=tmp/gs_docs
INDEX_PATH=tmp/vector_store.index
DOCUMENTS_PATH=tmp/documents.pkl1.Health Check: GET /health → { "status": "ok", "version": "0.1.0" }
2.List Routes: GET /routes → shows all registered endpoints.