Hybrid RAG over GitHub repos: BM25 + Pinecone + cited answers.
npm install @jchaffin/gh-rag``ts
import { createGhRag } from "@jchaffin/gh-rag";
const rag = await createGhRag({
openaiApiKey: process.env.OPENAI_API_KEY!,
pinecone: { apiKey: process.env.PINECONE_API_KEY!, index: "repo-chunks" },
});
await rag.ingest({ gitUrl: "https://github.com/owner/repo.git" });
const { text } = await rag.answer({
repo: "repo",
question: "Tell me about the payments project"
});
console.log(text);
`
For voice or streaming clients, pull context snippets fast without generating a full answer:
`ts
const rag = createGhRag({
openaiApiKey: process.env.OPENAI_API_KEY!,
pine: { index: / Pinecone index handle / } as any,
});
const snippets = await rag.ask({ repo: "repo", query: "auth flow", limit: 6 });
// Each snippet: { path, start, end, text }
`
Server endpoint (Fastify):
- Start: npm run build && npm run start{ "repo": "repo", "query": "auth flow", "limit": 6 }
- POST http://localhost:3000/ask with JSON
Notes:
- Set OPENAI_EMBED_MODEL to match your ingested index (e.g., text-embedding-3-small for speed). Ingestion also respects this.ask
- In-memory caching smooths identical queries for ~10s; embeddings cache for ~60s.
- Local BM25 index is optional. By default, ingest does not write any local files. To enable BM25 text ranking (used by when available), either pass writeBm25: true to ingestRepo/rag.ingest, or set GH_RAG_WRITE_BM25=1 and provide a workdir if you don't want ..
Ask questions from the command line after ingesting a repo into Pinecone.
- Env: set OPENAI_API_KEY, PINECONE_API_KEY, optional PINECONE_INDEX (default repo-chunks), optional GITHUB_TOKEN.
Examples:
`Build once
npm run build