Metadata-Version: 2.5
Name: wittgenstein-rag
Version: 0.3.1
Summary: A self-aware review layer for RAG pipelines: flags the retrieved text and answer sentences most likely to hide an LLM misreading, with a local interface.
Project-URL: Homepage, https://github.com/jonahablack/Wittgenstein
Project-URL: Source, https://github.com/jonahablack/Wittgenstein/tree/Cosmos/engine
Author: Wittgenstein RAG Reliability contributors
License: Apache-2.0
License-File: LICENSE
Keywords: hallucination,langchain,llamaindex,llm,rag,retrieval-augmented generation,verification
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.11
Requires-Dist: alembic>=1.14
Requires-Dist: fastapi>=0.115
Requires-Dist: httpx>=0.27
Requires-Dist: huggingface-hub>=0.30
Requires-Dist: llama-index-core>=0.12
Requires-Dist: model2vec>=0.10
Requires-Dist: numpy>=2.0
Requires-Dist: onnxruntime>=1.20
Requires-Dist: pydantic-settings>=2.6
Requires-Dist: pydantic>=2.9
Requires-Dist: pypdf>=6.0
Requires-Dist: python-multipart>=0.0.20
Requires-Dist: pyyaml>=6.0
Requires-Dist: rich>=13.9
Requires-Dist: spacy<3.9,>=3.8
Requires-Dist: sqlalchemy>=2.0
Requires-Dist: sqlmodel>=0.0.22
Requires-Dist: sse-starlette>=3.0
Requires-Dist: tokenizers>=0.20
Requires-Dist: typer>=0.13
Requires-Dist: uvicorn[standard]>=0.32
Provides-Extra: anthropic
Requires-Dist: anthropic>=2.0; extra == 'anthropic'
Provides-Extra: app
Requires-Dist: pywebview>=5.0; extra == 'app'
Provides-Extra: dev
Requires-Dist: httpx>=0.27; extra == 'dev'
Requires-Dist: mypy>=1.13; extra == 'dev'
Requires-Dist: pytest-cov>=6.0; extra == 'dev'
Requires-Dist: pytest>=8.3; extra == 'dev'
Requires-Dist: ruff>=0.8; extra == 'dev'
Requires-Dist: types-pyyaml; extra == 'dev'
Provides-Extra: langchain
Requires-Dist: langchain-core>=0.3; extra == 'langchain'
Provides-Extra: openai
Requires-Dist: openai>=2.0; extra == 'openai'
Provides-Extra: quality
Requires-Dist: fastembed>=0.9; extra == 'quality'
Description-Content-Type: text/markdown

# Wittgenstein

A review layer for retrieval-augmented generation (RAG). It runs beside the pipeline you
already have, checks every answer against the passages it came from, and points a
person to the few sentences worth a look: a dose that isn't in the source, a patient
group or condition that was dropped, a citation to the wrong passage, an answer that
says nothing at all.

It also knows the pipeline it is watching: how the documents were split, what the
search returned, and what never reached the model. So a flag can say whether the model
misread a passage or was never given the right one.

## Install and run

```bash
pip install wittgenstein-rag
wittgenstein start               # runs in the background
wittgenstein autostart enable    # optional: start at every login
```

Then watch your app's answers being checked, in the terminal or in a window:

```bash
wittgenstein watch               # in the terminal (also works over SSH; --plain for logs)
pip install "wittgenstein-rag[app]" && wittgenstein app    # in its own window
```

`wittgenstein status` and `wittgenstein stop` do what they say. Everything runs on your
machine; the first run downloads a small English language model (about 12 MB).

## Connect your app

Wittgenstein runs as its own process beside your app. It sees each request and checks
the answer afterwards, so it never adds latency or blocks a response.

**Any language: the model proxy.** Point your model client's base URL at Wittgenstein:

```
OpenAI-compatible   http://127.0.0.1:8100/proxy/openai/v1
Anthropic           http://127.0.0.1:8100/proxy/anthropic
```

Requests go on to the real API unchanged, streamed or not, with your own API key. Use
`wittgenstein start --openai-upstream http://localhost:11434` for Ollama or any other
OpenAI-compatible server.

**Python, no code changes:**

```bash
wittgenstein run python app.py
```

LangChain and LlamaIndex are hooked automatically; nothing is installed into your app's
environment.

**Or in code:**

```python
import wittgenstein.monitor as wm
wm.instrument()                                     # LangChain / LlamaIndex
wm.record(question, retrieved_chunks, answer)       # anything else
```

## Or call the API

```bash
curl -X POST http://127.0.0.1:8100/v1/check -H "content-type: application/json" -d '{
  "query": "What is the starting dose of metformin extended-release?",
  "candidates": [{"id": "c1", "text": "The recommended starting dosage is 500 mg once daily with the evening meal."}],
  "answer": "Start at 850 mg once daily. [1]"
}'
```

`summary.needs_review` in the response says whether a person should look, and each
flagged sentence says why. Full documentation is in the running app under **API**.

## Limits

Flags mean "a person should look", not "this is wrong". The checks are tuned on drug
labels; citation, empty-answer, document and context checks work in any domain. See the
[repository](https://github.com/jonahablack/Wittgenstein) for the evaluation behind it.

Supported by a grant from the [Cosmos Institute](https://www.cosmos-institute.org/).
