Skip to content
Projects

About

A highly contextualized retrieval system integrating Large Language Models (LLMs), embeddings, and a dynamic agent-driven framework. Supports PDF and audio file processing, conversational memory, and tool integration (search, calculator). Features advanced HNSW indexing and reranking for accurate information retrieval.

Design & Media

How these counts are measured

Measured star growth

in 24h
0
in 7 days
0
in 15 days
-1
in 1 month
Collecting history

Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.

README.md

Original
CORAG logo

CORAG

Chat with your PDFs and voice recordings in your browser.

Open-source RAG chat app for PDF and audio documents, written in Python with NiceGUI. Upload files, ask questions in plain language and get answers from Google Gemini, Anthropic Claude or a local model through Ollama that name the file (and PDF page) they came from, with HNSW vector search, cloud or local embeddings, and chats that are still there after a restart.

Apache-2.0 license Python 3.13 CI

Quick start · Why CORAG · What it does · How it works · Screenshots · FAQ · Docs

git clone https://github.com/harinaralasetty/CORAG.git && cd CORAG
pip install -r requirements.txt   # inside a Python 3.13 virtual environment
cp .env.example .env              # then add a Gemini or Claude API key, or an Ollama model
python server.py                  # open http://localhost:8080
CORAG pipeline: a PDF, MP3 or WAV file is extracted, split into 1,000-character chunks, embedded and stored in an HNSW index; a question is rephrased, the 20 nearest chunks are retrieved, and Gemini or Claude answers naming the source file

[!NOTE] With a Google Gemini or Anthropic Claude API key, each question is sent to that provider together with the matching passages from your files. To keep documents and questions on your machine, use a local Ollama model (at the default OLLAMA_BASE_URL) with the local embedding model. Audio is always transcribed by Google's Web Speech service.

Why CORAG

You have a stack of PDFs or recordings and want to ask them questions instead of scrolling through them.

  • Ask across several files. Add as many PDFs, text or Markdown files, or MP3 and WAV recordings to a chat as you like and ask about them together. Every passage is labelled with its file name, and PDF passages with their page, so answers can say where they came from.
  • Pick your model. Switch between Gemini, Claude and local Ollama models from a dropdown, per question.
  • Embeddings without a key. Use Google, Voyage or OpenAI embeddings, or a local sentence-transformers model that needs no API key.
  • Chats survive restarts. Chats, their file lists and their search indexes are saved in a local data/ folder.
  • Tools when they help. Gemini models can call a calculator and an optional web search (SerpApi or Tavily).
  • Small, readable code. Plain Python modules for ingestion, retrieval, inference and tools, with tests that need no API keys.

Quick start

You need Python 3.13 (the version the dependencies are pinned and tested on) and an API key from Google AI Studio (Gemini) or the Anthropic Console (Claude), or Ollama with a downloaded model (for example ollama pull llama3.2) to run without a key.

1. Get the code and install it in a virtual environment:

git clone https://github.com/harinaralasetty/CORAG.git
cd CORAG
python -m venv .venv
source .venv/bin/activate        # Windows: .venv\Scripts\activate
pip install -r requirements.txt

2. Add your key. Copy the example settings file, open .env in a text editor and fill in GOOGLE_API_KEY or ANTHROPIC_API_KEY, or set CORAG_OLLAMA_MODELS=llama3.2 (the names of your downloaded Ollama models, comma-separated):

cp .env.example .env

3. Start it and open http://localhost:8080:

python server.py

4. Use it. Drop a PDF, TXT, Markdown, MP3 or WAV file into the Documents panel on the right, wait for "Processed", then type a question. Pick the model and embedding provider in the left panel; start a new chat with +.

Or run it with Docker, with no Python setup: clone the repository, create .env as in step 2, then build and start the container and open http://localhost:8080:

docker build -t corag .
docker run --rm -p 127.0.0.1:8080:8080 -v "$PWD/.env:/app/.env:ro" -v corag-data:/data corag

Chats, indexes and the downloaded local embedding model are kept in the corag-data volume. To use Ollama running on your computer from the container with Docker Desktop, set OLLAMA_BASE_URL=http://host.docker.internal:11434/v1 in .env.

Settings, models, storage and tests

Environment variables (in .env, see .env.example):

Variable What it does
GOOGLE_API_KEY Gemini models and Google embeddings.
ANTHROPIC_API_KEY Claude models. To chat you need one of these two keys or CORAG_OLLAMA_MODELS.
CORAG_OLLAMA_MODELS Local Ollama models to offer, comma-separated, for example llama3.2,qwen2.5:7b. They appear as ollama/<name>. Not OLLAMA_MODELS, which Ollama itself reads as its model folder.
OLLAMA_BASE_URL Ollama's OpenAI-compatible endpoint. Default http://localhost:11434/v1.
VOYAGE_API_KEY, OPENAI_API_KEY Voyage or OpenAI embeddings.
SEARCH_PROVIDER Web search tool: serpapi (default, needs SERPER_API_KEY) or tavily (needs TAVILY_API_KEY). Optional.
CORAG_DATA_DIR Where chats and indexes are stored. Default data.
CORAG_HOST Interface the app listens on. Default 127.0.0.1, so only this computer can open it; there is no login, so set 0.0.0.0 only on a network you trust.

Defaults. The default model is gemini-2.5-flash, or claude-haiku-4-5-20251001 when only an Anthropic key is set, or the first CORAG_OLLAMA_MODELS entry when neither cloud key is set. The default embedding provider is the first with a key in the order Google, Voyage, OpenAI; with none, the local sentence-transformers/all-MiniLM-L6-v2 model is used (downloaded on first use).

Models in the picker (models_list in config.py): gemini-2.5-flash, gemini-2.5-pro, gemini-2.5-flash-lite, gemini-2.0-flash, gemini-flash-latest, gemini-pro-latest, claude-haiku-4-5-20251001, claude-sonnet-4-6, claude-opus-4-7, plus ollama/<name> for each CORAG_OLLAMA_MODELS entry.

Ollama context window. A CORAG prompt carries up to 20 passages of 1,000 characters plus chat history, and Ollama silently cuts prompts longer than its context window. If answers miss passages, start Ollama with a larger window, for example OLLAMA_CONTEXT_LENGTH=16384 ollama serve.

Embedding models (retrieval/embeddings_router.py): Google models/gemini-embedding-001, Voyage voyage-3-lite, OpenAI text-embedding-3-small, local sentence-transformers/all-MiniLM-L6-v2. A chat keeps the embedding provider it started with; pick another one in a new chat.

Chunking and search (config.py): chunks are 1,000 characters with 200 overlap (CHUNK_SETTINGS); the HNSW index uses M=30, ef_construction=500. The first 2,000 characters of a file (THEME_LENGTH) guide question rephrasing.

Uploads. Up to 200 MB per file, several files per chat. Uploading a file with the same name twice in a chat is skipped.

Storage. Chats are saved in data/chat_threads_info.json and each chat's index in data/<chat id>/. Delete the data/ folder to start fresh.

Dependencies. requirements.txt lists the direct dependencies; requirements-lock.txt has the exact pinned set. google_search_results provides the serpapi module; do not also install the separate serpapi package, it conflicts.

Tests:

pip install -r requirements-dev.txt
pytest

The tests use fake embeddings and models, so they need no API keys.

Legacy Indic PDFs

Some Telugu PDFs store glyph IDs in embedded Identity-H fonts without a ToUnicode map. Others use legacy Hindi or Marathi fonts such as Kruti Dev, Shree-Dev or DVB-TT. Install optional recovery in your CORAG environment:

python -m pip install -r requirements-indic.txt
python server.py

Then upload the PDF through Documents. CORAG checks each page for broken text or legacy fonts, runs indic-legacy-pdf on suspect pages and keeps PDF page citations. Documents shows "Telugu text recovered" for Telugu, or "Indic text recovered" for other supported scripts. The extraction method and recovery warnings appear in the server log.

Recovery supports embedded Telugu Identity-H glyph fonts and the converter's built-in Hindi/Marathi legacy mappings. Font coverage and layout affect accuracy; review recovered text, especially complex columns and ambiguous glyphs. Readable English and Unicode Indic pages keep the existing extraction path. Missing optional dependencies, failed recovery or output without improved Indic text retain the original PyPDF2 extraction. This path does not run OCR or translate text. Scanned PDFs still need OCR first. The default Docker image omits this optional dependency.

To run the offline synthetic example after installing recovery:

python scripts/demo_indic_pdf.py

What it does

Area Details
Documents PDF text extraction with ligature and line-break cleanup; plain text and Markdown (UTF-8); MP3 and WAV speech-to-text in segments of up to 45 seconds; several files per chat
Retrieval Question rephrased by the model, HNSW cosine search over 1,000-character chunks, top 20 re-sorted by similarity
Answers Nine Gemini and Claude models, or any local Ollama model; prompts carry passages, file names, PDF page numbers and chat history, and ask the model to name its sources
Embeddings Google, Voyage, OpenAI or a local sentence-transformers model
Tools Arithmetic-only calculator and web search via SerpApi or Tavily (Gemini models)
Chats Automatic chat names, chat list, per-chat documents, saved to disk between runs

How it works

CORAG components: documents and conversational memory feed an LLM agent, which uses dynamic prompting, embeddings with HNSW search and reranking, and a toolkit with search and calculator
  • An agent (inference/inference_manager.py) handles each question: it rephrases it, embeds it, pulls the closest passages from the chat's index and builds one prompt with the passages, file names and earlier messages.
  • Gemini models can call the calculator or web search; the tool output is added to the prompt and the model is asked again. Claude and Ollama models get the prompt without tools.
  • Retrieval always sends up to 20 passages, and answers are only as good as the extracted text: there is no OCR for scanned PDFs.

More detail in Architecture.

Screenshots

CORAG answering a question from an uploaded plum orchard handbook PDF: model picker set to ollama/qwen2.5:3b and local embeddings on the left, the question and an answer citing late July and 4 degrees Celsius in the middle, the PDF in the Documents panel on the right

The current interface, running fully on one computer: a local qwen2.5:3b model through Ollama, local embeddings and no API key. The answer comes from the uploaded two-page PDF.

FAQ

Is it free? The code is free under Apache-2.0. Google, Anthropic and the optional embedding and search providers bill API use under their own pricing. Ollama models at the default OLLAMA_BASE_URL run on your own computer at no charge.

Does my data leave my computer? With Gemini or Claude, yes: your question and the retrieved passages go to that provider. With an Ollama model at the default OLLAMA_BASE_URL and the local embedding model, documents and questions stay on your computer. Audio always goes to Google's Web Speech service. Extracted text, chats and indexes are stored only in the local data/ folder. With the local embedding model, document text is not sent anywhere for embedding.

Which files can I upload? PDFs with a text layer, .txt and .md files in UTF-8, and MP3 or WAV audio (recordings longer than 60 minutes are refused). Scanned PDFs need OCR first.

Can I change the embedding provider in an existing chat? No. Vectors from different providers cannot be mixed, so a chat keeps its first provider. Start a new chat to use another.

Why don't Claude and Ollama models use the calculator or web search? Tools are wired through LangChain for Gemini only; the other models get a plain prompt.

Can several people share one instance? It is built as a single-user local app: every open browser tab sees the same chats.

Documentation

Contributing

Issues and pull requests are welcome. Run pytest (after pip install -r requirements-dev.txt) before opening a pull request; the tests need no API keys. Questions or feedback: Hari Naralasetty on LinkedIn.

License

Apache-2.0

Explore related projects

Loading…