Skip to main content

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

Project description

Tensor Truth

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 Streamlit, with high level of configurability for the pipeline.

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.13+):

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.13
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, pre-built indexes will auto-download from Google Drive (takes a few minutes). Also a small qwen2.5:0.5b will be pulled automatically for assigning automatic titles to chats.

Index Downloads

Pre-built indexes download automatically on startup. Note that Google Drive has rate limits, so if it refuses to download, try manually from indexes.tar.

Extract to ./indexes in the project root.

For details on the contents of this archive, see config/api.json and config/papers.json. These are my curated lists of useful libraries and research papers. Feel free to fork and set up your own indexes. See below instructions on how to build the indexes.

Requirements

Tested on:

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

Minimum recommended: 16GB RAM, Python 3.13+. GPU optional but significantly faster.

Recommended Models

Any Ollama model works, but these are tested:

General Purpose:

ollama pull deepseek-r1:8b     # Balanced
ollama pull deepseek-r1:14b    # High quality
ollama pull deepseek-r1:32b    # Best quality (24GB+)

Code/Technical Docs:

ollama pull deepseek-coder-v2:16b
ollama pull deepseek-coder-v2

DeepSeek-R1 models include chain-of-thought reasoning. Coder-V2 variants are optimized for technical content and work particularly well with programming documentation.

Building Your Own Indexes

Pre-built indexes cover common libraries, but you can create custom knowledge bases:

Scrape Documentation:

tensor-truth-docs --list          # Show available libraries
tensor-truth-docs pytorch         # Scrape PyTorch docs

Fetch Research Papers:

tensor-truth-papers --config ./config/papers.json --category your_category --ids 2301.12345
tensor-truth-papers --rebuild your_category

Build Vector Index:

tensor-truth-build --modules module_name

Configuration

This system is configured for personal research workflows with these assumptions:

  • ChromaDB for vector storage (persistent, single-process)
  • HuggingFace sentence-transformers for embeddings
  • BGE cross-encoder models for reranking
  • Ollama for local LLM inference
  • All processing runs locally

If you need different chunking strategies or retrieval parameters, you'll need to modify the source files. The current setup is tuned for technical documentation and research papers.

License

MIT License - see LICENSE for details.

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

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.1.1.tar.gz (35.9 kB 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.1.1-py3-none-any.whl (37.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for tensor_truth-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3b74dfbc78d30b58b3c692a3911bf449c0c62d2ef2420e68d5ad5bf089ddfbe2
MD5 74cbe1c37934a84179123f0225eb5548
BLAKE2b-256 917d1d1e7bbb76b57b24acfa3164c97b9c17fffe83402b5ca1c76d9be8f8f4f2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tensor_truth-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 37.8 kB
  • 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.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 af3efd03b1bab7f2ec935b6cea436e804aa9457cc0cd7dcd89e1067e8fea1823
MD5 69155c7663e6f4dfdb052aa393f5ccaf
BLAKE2b-256 c2a053a0bee1c17e8c753c5602a3ffdd08f78b843527ecffb5a92a3953c4278b

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