JAGADISWAR / LEARNINGS / RAGSPHERE
AI / RETRIEVAL

What I learned
building RAGSphere.

Functional local applicationRAGLLMsEmbeddingsPython

An AI-focused build exploring retrieval-augmented generation, contextual search and grounded responses instead of relying on generation alone.

LEARNINGS / RAGSPHEREFUNCTIONAL LOCAL APPLICATIONAMBATI JAGADISWAR REDDY
01 / OVERVIEW & STATUS

What it is, and where it stands.

RAGSphere lets you upload PDF and TXT documents, choose one or more of them, and ask questions. Answers are generated from passages retrieved from only the selected documents, and each answer comes with its sources.

Everything runs locally: a Flask backend, a ChromaDB vector store, and models served by Ollama. It can run directly with Python or through Docker Compose.

Status
Functional, Dockerized local application
Models (via Ollama)
llama3.2:3b for generation, nomic-embed-text for embeddings
Backend
Python, Flask, PyMuPDF for text extraction
Vector store
ChromaDB, persistent, cosine similarity
Frontend
Plain HTML, CSS and JavaScript
Deployment
Local or Docker. A public deployment would need a hosted inference environment (per the README)
02 / WHAT I LEARNED

Lessons from the build.

Most of the learning was about the parts around the model: how text is chunked, how retrieval is scoped, and how an answer is kept honest.

LESSON / 01

Retrieval decides answer quality

Documents are split into chunks of about 900 characters with 180 characters of overlap. A chunk ends at a sentence or line break only when that break falls past the halfway point, so chunks stay readable without becoming tiny.

LESSON / 02

Scope retrieval to what the user chose

Each chunk is stored with its document ID, and queries filter on the selected document IDs. Single and multi-document questions both stay inside the user’s selection, and with nothing selected the app returns nothing instead of guessing.

LESSON / 03

Grounding is both a prompt and an interface

The system prompt tells the model to answer only from the supplied context and to say so when the context is not enough. Temperature is 0.2. Sources (document, page, chunk, relevance, snippet) are returned so the user can check the claim.

LESSON / 04

Local models change the architecture

Ollama runs on the host while the app can run in a container, so the container reaches it through host.docker.internal. The model endpoint is configurable through an OLLAMA_URL environment variable.

TECHNICAL CONCEPTS

Embeddings and cosine similarity

Chunks and questions are embedded with nomic-embed-text and compared in a cosine-space ChromaDB collection.

Chunking with overlap

Overlap keeps context that would otherwise be cut at a chunk boundary.

Metadata filtering

Vector search is restricted with a where filter on document_id, using $in for multi-document queries.

Page-aware extraction

PDFs are read page by page so each chunk carries a page number that can be cited.

Prompt construction

Retrieved chunks are formatted as numbered sources with document and page, followed by the last few turns of conversation and the question.

Persistence and containers

Uploads, a document index and the vector database live in a data directory that is mounted into the container so they survive restarts.

03 / CHALLENGES & DECISIONS

Challenges and engineering decisions.

Where the build pushed back, and what I decided to do about it.

Grounding

Keeping answers inside the documents

CHALLENGEA language model will happily answer from its own knowledge.

DECISIONThe prompt forbids outside knowledge and sets a fixed fallback sentence. The pipeline also short-circuits: if retrieval finds nothing, it replies without calling the model at all.

Citations

Showing where an answer came from

CHALLENGEAn answer without a source is hard to trust or verify.

DECISIONPage and chunk numbers are stored as metadata at ingestion. Sources are de-duplicated by document, page and chunk, and each snippet is trimmed to a readable length.

Multi-document

Querying several documents without mixing in others

CHALLENGESearching the whole library would pull in unrelated passages.

DECISIONRetrieval filters to the selected document IDs before ranking, then returns the top five chunks.

Environment

A containerized app talking to a host-side model

CHALLENGEInside Docker, localhost no longer points at the machine running Ollama.

DECISIONThe Compose file maps host.docker.internal to the host gateway and passes the Ollama address as an environment variable.

Honest scoring

Showing a relevance number without over-claiming

CHALLENGECosine distance is not a calibrated probability.

DECISIONThe code labels the percentage as an approximate similarity derived from distance, and it is shown as a relevance hint, not as confidence.

04 / POTENTIAL IMPROVEMENTS

What I would improve next.

Ideas grounded in what the current code and documentation say is missing.

From prototype
to something sturdier.

  • Support scanned PDFs. Extraction reads only the text layer, so image-only PDFs are rejected as having no readable text. OCR would fix that.
  • Embed chunks in batches. Ingestion currently makes one embedding request per chunk, which is slow for large documents.
  • Build a small evaluation set of questions with expected pages, so retrieval changes can be measured instead of judged by eye.
  • Add a relevance threshold or re-ranking step. Retrieval intentionally returns the top matches without rejecting weak ones.
  • Replace debug prints in the retrieval path with proper logging, and plan a hosted-inference option for public deployment.

The code is the artifact.
The learning is the leverage.

Concise notes on RAGSphere, written to make the decisions behind it easy to discuss in a review, interview or collaboration.