Skip to main content

Local RAG pipeline for fixing LLM hallucinations using high-precision documentation indexing.

Project description

logo

Python 3.11+ PyPI Docker Hub Tests

A local RAG pipeline for reducing hallucinations in LLMs by indexing technical documentation and research papers. Built for personal use on local hardware, shared here in case others find it useful. Web UI is built with React, with high level of configurability for the pipeline.

Note: For the moment, this is very much a hobby project. The app has no authentication or multi-user support and is designed to run locally on your own machine. If there's interest in production-ready deployment features, I can add them (feel free to make a request via issues).

What It Does

Indexes technical documentation and research papers into vector databases, then uses retrieval-augmented generation to ground LLM responses in source material. Uses hierarchical node parsing with auto-merging retrieval and cross-encoder reranking to balance accuracy and context window constraints.

Quick Start

Install the tool via PyPI. But before you do, I advise you prep the environment because of large volume of dependencies (use Python 3.11+):

python -m venv venv
source venv/bin/activate  # or .\venv\Scripts\activate(.ps1) on Windows CMD/PowerShell

Or via conda:

conda create -n tensor-truth python=3.11
conda activate tensor-truth

If using CUDA, make sure to first install the appropriate PyTorch version from pytorch.org. I used torch 2.9 and CUDA 12.8 in environments with CUDA.

If not, just install tensor-truth via pip, which includes CPU-only PyTorch.

pip install tensor-truth

Make sure ollama is installed and set up. Start the server:

ollama serve

Run the app:

tensor-truth

On first launch, the app will prompt you to download pre-built indexes from HuggingFace Hub (takes a few minutes). A small qwen2.5:0.5b model will also be pulled for assigning automatic titles to chats.

Docker Deployment

For easier deployment without managing virtual environments or CUDA installations, a pre-built Docker image is available on Docker Hub. This approach is useful if you want to avoid setting up PyTorch with CUDA manually, though you still need a machine with NVIDIA GPU and drivers installed.

Pull the image:

docker pull ljubobratovicrelja/tensor-truth:latest

Run the container:

docker run -d \
  --name tensor-truth \
  --gpus all \
  -p 8000:8000 \
  -v ~/.tensortruth:/root/.tensortruth \
  -e OLLAMA_HOST=http://host.docker.internal:11434 \
  ljubobratovicrelja/tensor-truth:latest

Access the app at http://localhost:8000

See DOCKER.md for complete Docker documentation, troubleshooting, and advanced usage.

Data Storage

All user data (chat history, presets, indexes) is stored in ~/.tensortruth on macOS/Linux or %USERPROFILE%\.tensortruth on Windows. This keeps your working directory clean while maintaining persistent state across sessions.

Pre-built indexes are hosted on HuggingFace Hub and can be downloaded through the web UI on first launch.

For index contents, see config/sources.json. This is a curated list of useful libraries and research papers. Fork and customize as needed.

Requirements

Tested on:

  • MacBook M1 Max (32GB unified memory)
  • Desktop with RTX 3090 Ti (24GB VRAM)

If you encounter memory issues, consider running smaller models. Also keep track of what models are loaded in Ollama, as they consume GPU VRAM, and tend to stuck in memory until Ollama is restarted.

Recommended Models

Any Ollama model works, but I recommend these for best balance of performance and capability with RAG:

General Purpose:

ollama pull deepseek-r1:8b     # Balanced
ollama pull deepseek-r1:14b    # More capable

Note that, even though pure Ollama can run deepseek-r1:32b, with RAG workflow it is likely to struggle on 24GB 3090 for e.g.

Code/Technical Docs:

For coding, deepseek-coder-v2 is a strong choice:

ollama pull deepseek-coder-v2:16b 

Or, the smaller qwen2.5-coder, holds up well with API docs on coding aid.

ollama pull qwen2.5-coder:7b 

Autonomous Agents

Tensor-Truth supports autonomous agents via Model Context Protocol (MCP) integration. Agents can use external tools to complete tasks beyond the knowledge base.

Example - Web Research Agent:

/browse What are the latest features in Python 3.13?

Agents can also be triggered through natural language (e.g., "Research the latest transformer papers"). The agent system is extensible via custom MCP server configurations.

Development

For frontend development, the React UI runs as a separate Vite dev server with hot-reload, proxying API calls to the backend:

# Terminal 1: Start the API server with auto-reload
tensor-truth --reload

# Terminal 2: Start the React dev server (port 5173)
tensor-truth-ui

The production tensor-truth command serves the bundled React frontend directly from port 8000 — no separate frontend process needed.

Building Your Own Indexes

Pre-built indexes cover common libraries, but you can create custom knowledge bases for your specific needs.

Quick Start

Interactive Mode (Recommended):

tensor-truth-docs --add    # Guided wizard for adding libraries, papers, or books

Command-Line Mode:

tensor-truth-docs --list                              # Show all available sources
tensor-truth-docs pytorch_2.9 numpy_2.3               # Fetch library documentation
tensor-truth-docs --type papers --category foundation_models --arxiv-ids 1706.03762  # Add specific papers
tensor-truth-build --modules foundation_models        # Build vector index

Session PDFs:

Upload PDFs directly in the web UI to create per-session indexes. Only standard PDF files are supported currently.

Detailed Documentation

For comprehensive guides on building custom indexes, see docs/INDEXES.md, which covers:

  • Interactive source addition workflow
  • Adding libraries, papers, and books
  • Chunk size optimization strategies
  • Advanced workflows and troubleshooting

License

MIT License - see LICENSE for details.

Built for personal use but released publicly. Provided as-is with no warranty.

Disclaimer & Content Ownership

1. Software License: The source code of tensor-truth is licensed under the MIT License. This covers the logic, UI, and retrieval pipelines created for this project.

2. Third-Party Content: This tool is designed to fetch and index publicly available technical documentation, research papers (via ArXiv), and educational textbooks.

  • I do not own the rights to the indexed content. All PDF files, textbooks, and research papers fetched by this tool remain the intellectual property of their respective authors and publishers.
  • Source Links: The configuration files (config/sources.json, etc.) point exclusively to official sources, author-hosted pages, or open-access repositories (like ArXiv).
  • Usage: This tool is intended for personal, non-commercial research and educational use.

3. Takedown Request: If you are an author or copyright holder of any material referenced in the default configurations or included in the pre-built indexes and wish for it to be removed, please open an issue or contact me at ljubobratovic.relja@gmail.com, and the specific references/data will be removed immediately.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tensor_truth-0.2.0.tar.gz (2.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tensor_truth-0.2.0-py3-none-any.whl (2.1 MB view details)

Uploaded Python 3

File details

Details for the file tensor_truth-0.2.0.tar.gz.

File metadata

  • Download URL: tensor_truth-0.2.0.tar.gz
  • Upload date:
  • Size: 2.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for tensor_truth-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e779dc2a27af9e668f70062078ea44001869b13db92ec7d697886d8f4bf18979
MD5 65bdde3ccb344daef4c2a8e0d59321b7
BLAKE2b-256 d6a6b7ecbfe41235dbce19c941ec01c65d9a5ec567e6d801f075bb6fd203ce01

See more details on using hashes here.

File details

Details for the file tensor_truth-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: tensor_truth-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 2.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for tensor_truth-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 617b812665a969eb3a41632598110badb36b32d02ee24336487d9f9818756353
MD5 7948bc924e6df6dc37b13d9cd9107148
BLAKE2b-256 7fcd85c68d3542c6769b99706d97ea43cc6ef7ce3b01476e09282867b2e942b4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page