Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Contexto

A semantic search engine for .txt and .md files. The goal is to actually understand what you're asking instead of just matching keywords. Upload a document, query it in plain English, and get back the specific sentence that answers you, not just the paragraph it happens to be sitting in.

Quick start

Not deployed yet. The backend still needs session isolation before it can go live safely, since right now every upload shares one global collection, which would turn into a multi-user bug pretty fast. Run it locally for now, instructions below.

Features

  1. Sentence-boundary-aware chunking. Uses pysbd to split documents on real sentence boundaries instead of blind character slicing, with a hard-split fallback for the rare sentence that's still too long on its own
  2. Two-tiered reranking engine. ChromaDB handles macro retrieval with explicit cosine-distance search, then a sentence-level reranker re-scores every sentence inside the retrieved chunks using the same already-loaded embedding model, so RAM never doubles on a 512MB free-tier box
  3. Highlighted-sentence responses. Every search result comes back with score, highlighted_sentence, and sentence_score, so the UI can point at the exact sentence that matched instead of the whole chunk
  4. Fully local embeddings. Runs all-MiniLM-L6-v2 via sentence-transformers on-device, no external API calls, no data leaving the machine
  5. Rich chunk metadata. Each chunk tracks start_sentence, end_sentence, start_char, and end_char for precise provenance back to the source file

Running it locally

Requires Python 3.11+ and Node 18+.

Backend

cd backend
python -m venv venv
source venv/bin/activate  # or venv\Scripts\activate on Windows
pip install -r requirements.txt
uvicorn app.main:app --reload

API docs at http://127.0.0.1:8000/docs.

Frontend

cd frontend
npm install
npm run dev

Then open http://localhost:3000.

No environment variables or external services are required — everything, including the embedding model, runs locally.

How it works

The hard problem here isn't retrieval, it's precision. ChromaDB is great at finding the right paragraph, but a paragraph isn't an answer, a sentence is. So Contexto retrieves at the chunk level first, since that's cheap and it's what ChromaDB is good at, then re-embeds and cosine-scores every individual sentence inside the top chunks to find the one that actually matters. The reranker reuses the already-loaded all-MiniLM-L6-v2 instance instead of spinning up a second model, which matters a lot on Render's 512MB free tier, since loading the model twice would blow the memory budget.

Chunking took a similar amount of care. Fixed-size character chunking is the obvious first pass, but it slices sentences in half at arbitrary offsets and quietly destroys the semantic signal you're trying to embed in the first place. Contexto chunks on real sentence boundaries with pysbd instead, and falls back to a hard split for the rare sentence that's still too long on its own.

Session isolation is the one piece that's been deliberately put off. Right now every upload lands in a single shared ChromaDB collection, which is fine for local single-user testing but not safe once more than one person is using it at a time. The fix is to tag each chunk with a client-side UUID session_id and filter queries by it. It's designed but not built yet, and it's a hard blocker before anything gets deployed.

Tech stack

Layer Library
Frontend Next.js, Tailwind CSS, TypeScript
Backend Python, FastAPI, Uvicorn
Vector DB ChromaDB (embedded, ephemeral storage on the backend by design)
Embeddings sentence-transformers (all-MiniLM-L6-v2)
Chunking pysbd for sentence-boundary detection
Deployment (planned) Vercel (frontend) + Render (backend, via Docker)

Status

Backend Phase 1 (chunking and reranking) is done. Frontend Phase 2 is still in design: a dark-mode, lab-instrument-inspired UI with a near-black background, a desaturated cyan accent, amber reserved for highlighted sentences, and monospace for numbers, but no components built yet. Session isolation and deployment (Phase 3) come after that.

Credits

Built on top of a few open-source projects doing the heavy lifting:

Built by Arman Singh

About

Local semantic search engine for documents. Powered by Next.js, FastAPI, ChromaDB, and Sentence Transformers.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages