How mohdsaadma07/code-sense works
This is a single-service FastAPI backend that implements a local Retrieval-Augmented Generation (RAG) workflow:
• Inputs: local text files (upload) + public GitHub repos (URL)
• Processing: chunking → embeddings (HuggingFace all-MiniLM-L6-v2) → storage in FAISS
• Query modes:
• Similarity search (raw retrieval)
• RAG answer generation using a local Llama GGUF model via llama-cpp-python
Entry point & composition
• code-app/app/main.py: FastAPI app creation + router registration (composition root)
• code-app/app/config.py: environment/config (e.g., .env, GitHub token, paths)
API layer (controllers)
• code-app/app/routes/ingest.py: local file ingestion endpoints
• code-app/app/routes/github.py: GitHub ingestion endpoints
• code-app/app/routes/query.py: similarity search endpoints
• code-app/app/routes/llama.py: RAG query endpoints
Domain / data contracts
• code-app/app/models/document.py: Pydantic models for request/response + document/chunk structures
Service layer (core logic)
• code-app/app/services/embeddings.py: embedding model initialization + embedding calls
• code-app/app/services/storage.py: FAISS index management + persistence to disk
• code-app/app/services/rag.py: retrieval orchestration + prompt context assembly (core RAG logic)
• code-app/app/services/llama_rag.py: Llama inference wrapper / RAG execution with local LLM
• code-app/app/services/github_loader.py: GitHub API interaction + repository file traversal + content extraction
• code-app/app/services/github.py: likely higher-level GitHub ingestion coordination (depends on repo structure)
Storage / artifacts (infrastructure)
• vectorstore/index.faiss + vectorstore/index.pkl: persisted FAISS index + metadata
• .env: optional token + config
Include:
• User / Client (Swagger UI, curl, any HTTP client)
• Code-Sense FastAPI Service
• GitHub (external system) (GitHub API / raw content)
• Local Disk (vectorstore persistence + model file)
• Client → FastAPI (HTTP)
• FastAPI → GitHub (HTTPS, optional auth token)
• FastAPI ↔ Local Disk (read/write FAISS index + read model file)
• (Optionally) FastAPI → HuggingFace model runtime (logical dependency; it runs locally but conceptually an “embedding subsystem”)
Ingestion: local file (/ingest/)
Client -> routes/ingest.py -> services (chunking) -> services/embeddings.py -> services/storage.py -> FAISS index on disk
• Explicitly show Text Splitter (RecursiveCharacterTextSplitter) as a sub-component inside ingestion flow.
Ingestion: GitHub (/github/ingest)
Client -> routes/github.py -> services/github.py -> services/github_loader.py -> (GitHub API) -> extracted text -> splitter -> embeddings -> storage -> FAISS on disk
• GitHub token from .env going into GitHub loader as configuration (optional path).
Query: similarity (/query/)
Client -> routes/query.py -> services/embeddings.py (embed query) -> services/storage.py (similarity search) -> results
Query: RAG + Llama (/llama/query)
Client -> routes/llama.py -> services/rag.py (retrieve top-k chunks) -> services/llama_rag.py (prompt + inference) -> local Llama GGUF -> response
• Make it visually clear that retrieval happens *before* LLM generation and that the context chunks are injected into the prompt.
• Layered architecture: Routes → Services → Storage/External systems
• Pipeline pattern for ingestion: parse → split → embed → index
• RAG pattern for answering: embed query → retrieve → augment prompt → generate
• Local-first privacy: LLM inference and vector store are on local disk (no hosted LLM)