Skip to content

Repository files navigation

Welcome to Sharp Docs

Chat with any documentation. Ingest doc URLs, then ask questions and get streaming, source-cited answers powered by Google Gemini and a hybrid (vector + BM25) retriever.

Features

  • Ingestion pipeline — fetch a URL, strip boilerplate, chunk, embed, and store.
  • Hybrid retrieval — cosine vector search fused with BM25 keyword ranking.
  • Streaming chat — token-by-token SSE responses with inline source citations.
  • Disk persistence — the vector store is snapshotted to data/store.json and rehydrated on startup.
  • Observability — in-memory trace ring buffer plus optional OpenTelemetry OTLP export.
  • Retrieval eval — Precision@k, Recall@k, and MRR benchmarks.

Prerequisites

Setup

npm install --legacy-peer-deps
cp .env.example .env # then set GOOGLE_API_KEY

The --legacy-peer-deps flag is required because @langchain/community declares an optional peer on html-to-text@^9 while this project uses html-to-text@^10.

Note: Documents and queries are embedded with Gemini's asymmetric retrieval task types (RETRIEVAL_DOCUMENT / RETRIEVAL_QUERY). If you have a store from an older build, re-ingest your URLs so passages and queries share the same embedding space.

Environment variables

VariableRequiredDefaultDescription
GOOGLE_API_KEYyesGoogle AI Studio key for chat + embeddings
GOOGLE_CHAT_MODELnogemini-2.5-flashChat model
GOOGLE_EMBEDDING_MODELnogemini-embedding-001Embedding model
OTEL_EXPORTER_OTLP_ENDPOINTnoEnables OTLP trace export when set
OTEL_SERVICE_NAMEnosharp-docsService name reported to OTLP

Development

npm run dev # start the dev server at http://localhost:3000
npm test# run the Vitest suite
npm run lint # run ESLint
npm run build # production build

API

RouteMethodDescription
/api/ingestPOST{ urls: string[] } (max 10, http(s) only) → ingestion results
/api/chatPOST{ query, history } → SSE stream (sourcestoken* → done / error)
/api/storeGETIngested sources and total chunk count
/api/store?url=...DELETERemove all chunks for a source URL
/api/tracesGETAggregate trace stats and recent traces

Retrieval evaluation

With documents already ingested:

npx tsx src/lib/eval.ts

Prints Precision@1/3/5, Recall@3/5, and MRR over auto-generated queries.

Project structure

src/
instrumentation.ts startup store preload + OTLP init
app/
page.tsx chat UI (client)
api/ chat | ingest | store | traces route handlers
lib/
rag.ts retrieval + streaming chat chain
observability.ts in-memory trace buffer + stats
telemetry.ts OTLP exporter
eval.ts / gen-eval.ts retrieval + generation evaluation
ingestion/ fetcher | chunker | embedder | pipeline
vectorstore/ store | bm25 | persistence

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages