RAG-Powered Semantic Code Search & AI Chat for Any GitHub Repository
CodeLens lets you paste any public GitHub repo URL, indexes the entire codebase into a vector database, and then lets you ask questions in plain English — getting precise, context-aware answers grounded in the actual source code.
| Feature | Description |
|---|---|
| RAG Pipeline | Retrieval-Augmented Generation using FAISS vector search + Gemini LLM |
| File Explorer | Interactive file tree with extension-based icons and search filtering |
| AI Chat | Ask questions about any codebase in natural language |
| Conversation Mode | Multi-turn chat with sliding window context (last 10 messages) |
| Context Sources | See exactly which code chunks were used, with similarity scores |
| Auto Summary | Generates a 3-sentence codebase overview on indexing |
| Model Fallback | Automatically rotates through Gemini models if quota is hit |
User Question
↓
① EMBED the question (Gemini Embedding API)
↓
② IT retrieve's top-8 most similar code chunks (FAISS cosine similarity)
↓
③ AUGMENT the LLM prompt with retrieved chunks as context
↓
④ GENERATE answer using Gemini Flash
↓
Answer + Source Citations + Similarity Scores
- Backend: Python, FastAPI, Uvicorn
- Vector DB: FAISS (Facebook AI Similarity Search)
- Embeddings: Google Gemini Embedding API (
gemini-embedding-001) - LLM: Google Gemini Flash (with automatic model fallback)
- Text Splitting: LangChain
RecursiveCharacterTextSplitter - Git: GitPython for repository cloning
- Frontend: Vanilla HTML/CSS/JS with Marked.js + Highlight.js
git clone https://github.com/upadhyay74aman/Code_Lens.git
cd Code_Lenspip install -r requirements.txt- Go to Google AI Studio
- Create a free API key
GEMINI_API_KEY=your_api_key_here
python main.pyOr:
uvicorn main:app --port 8000Navigate to http://localhost:8000 and start exploring codebases!
| Method | Endpoint | Description |
|---|---|---|
GET |
/ |
Serves the frontend UI |
POST |
/api/index |
Clone & index a GitHub repository |
POST |
/api/query |
Single Q&A semantic search |
POST |
/api/chat |
Multi-turn conversation mode |
GET |
/api/filetree |
Get the indexed repo's file tree |
GET |
/api/status |
Get indexing statistics |
Code_Lens/
├── main.py # FastAPI backend (RAG pipeline, FAISS, Gemini)
├── index.html # Frontend UI (IDE-style dark theme)
├── requirements.txt # Python dependencies
├── .env # API key (not committed)
├── .gitignore # Git ignore rules
└── README.md # This file
-
Indexing Phase: Repository files are split into ~1000 character chunks with 200 char overlap. Each chunk is embedded using Gemini's embedding model and stored in a FAISS Inner Product index.
-
Query Phase: Your question is embedded using the same model, then FAISS finds the top-8 most semantically similar code chunks via cosine similarity.
-
Generation Phase: The retrieved chunks are injected into a carefully crafted prompt, and Gemini Flash generates a grounded answer citing specific files and line numbers.