git-wiki
core-archtecture
On this page
Why Async: Instant Receipts, Slow Cooking
01
Notes
When you order a pizza on Swiggy, the app gives you an Order ID in 50 milliseconds instead of freezing your screen for 25 minutes while the kitchen bakes it.
Similarly, an Express server will timeout if an HTTP request stays open for 2 minutes while downloading, splitting, and embedding a GitHub codebase.
Calling `POST /api/index` creates a job marked 'queued', fires a background event to Inngest, and returns a `jobId` immediately.
The client browser polls `GET /:jobId` every 2 seconds to check if status flipped from 'running' to 'completed'.
Step Checkpoints: Never Start Over
02
Notes
If an IRCTC Tatkal payment fails after seat allocation, you want the app to retry only the UPI payment, not restart coach selection from zero.
Inngest wraps every heavy operation inside `step.run()`, checkpointing intermediate outputs to durable storage.
If GitHub file download succeeds but Pinecone vector upsert fails due to a network glitch, Inngest retries ONLY the Pinecone step.
This prevents wasted OpenAI API billing and stops your app from exhausting GitHub's 5,000 requests-per-hour rate limit.
Write Path: Indexing Repository Code
03
Notes
Triggered by `repo/index.requested`, Step 1 fetches up to 200 source files from GitHub's tree API.
Step 2 runs locally on the CPU, splitting files into 1,000-character LangChain text chunks with a 150-character overlap to preserve syntax boundaries.
Step 3 sends chunks to OpenAI `text-embedding-3-small` and upserts vectors into Pinecone under an isolated namespace formatted as `owner-repo`.
Once vectors are written, the job marks itself 'completed' and records final metrics like 140 files and 520 chunks.
Read Path: RAG Similarity Search
04
Notes
When a developer submits a question via `POST /api/chat`, Express responds with HTTP 202 and delegates work to `ask-question`.
This function never touches GitHub; it embeds the user query and asks Pinecone for the top 5 (k=5) closest vector chunks inside that repo's namespace.
It injects those 5 code chunks into a strict system prompt: 'Answer using this repo context only' to eliminate AI hallucinations.
GPT-4o-mini generates the response within 2 to 4 seconds, returning both the Markdown answer and the specific source file paths.
Two Paths, One Vector Namespace
05
Notes
The write path (`index-repo`) runs once per repository commit, converting hundreds of source files into searchable vectors.
The read path (`ask-question`) runs hundreds of times as teammates ask multiple questions about the codebase.
Neither function directly invokes the other; their only shared touchpoint is the isolated Pinecone namespace `owner-repo`.
If a user queries a repository before indexing completes, Pinecone returns 0 vectors and the LLM safely reports empty context.