Builds PaperTrail from the base skeleton into a full evidence-verification platform for the "Built with Claude: Life Sciences" hackathon (Builder Track). New named-user features (Build Beyond the Bench): - Lab Notebook Companion — rough bench notes -> structured, searchable, grounded experiment records (lib/labNotebook, /console/lab-notebook, migration 0059) - Clinical Trial Matcher — de-identified patient notes -> ranked eligible ClinicalTrials.gov trials with per-criterion inclusion/exclusion reasoning (lib/trialMatcher, /console/trial-matcher, migrations 0060) Platform: - Deterministic verification moat (biostats recompute, exact-span grounding) - 11 biomedical evidence engines (FAERS, GWAS, Open Targets, ChEMBL, ClinVar, PharmGKB, PubTator, DDI, repurposing, biomarker, unified verifier) - Evidence Intelligence (KG, dossier, provenance/export, RWE) + enterprise governance (RBAC, /api/v1 gateway, metering, audit chain, retention) - 17 OSS projects assimilated into native TypeScript on our stack (backend/engines retained + credited in NOTICE) - Multi-format upload (PDF/DOCX/XLSX/CSV/MD/TXT), logo, marketing site - Next.js 16 upgrade, benchmark harness (honest smoke-test caveat) Licensing: Apache-2.0 (LICENSE + NOTICE).
7.4 KiB
There are many amazing LLMs and embedding models that can be run locally. R2R fully supports using these models, giving you full control over your data and infrastructure.
Running models locally can be ideal for sensitive data handling, reducing API costs, or situations where internet connectivity is limited. While cloud-based LLMs often provide cutting-edge performance, local models offer a compelling balance of capability, privacy, and cost-effectiveness for many use cases.
### Serving Local Models For this cookbook, we'll serve our local models via Ollama. [You may follow the instructions on their official website to install.](https://ollama.com/)You can also follow along using LM Studio. To get started with LM Studio, see our Local LLM documentation.
R2R supports LiteLLM for routing embedding and completion requests. This allows for OpenAI-compatible endpoints to be called and seamlessly routed to, if you are serving local models another way.
We must first download the models that we wish to run and start our ollama server. The following command will 'pull' the models and begin the Ollama server via http://localhost:11434.
ollama pull llama3.1
ollama pull mxbai-embed-large
Ollama has a default context window size of 2048 tokens. Many of the prompts and processes that R2R uses requires larger window sizes.
It is recommended to set the context size to a minimum of 16k tokens. The following guideline is generally useful to determine what your system can handle:
- 8GB RAM/VRAM: ~4K-8K context
- 16GB RAM/VRAM: ~16K-32K context
- 24GB+ RAM/VRAM: 32K+ context
To change the default context window you must first create a Modelfile for Ollama, where you can set num_ctx:
echo 'FROM llama3.1
PARAMETER num_ctx 16000' > Modelfile
Then you must create a manifest for that model:
ollama create llama3.1 -f Modelfile
Then, we can start the Ollama server:
ollama serve
Configuring R2R
Now that our models have been loaded and our Ollama server is ready, we can launch our R2R server.
The standard distribution of R2R includes a configuration file for running llama3.1 and mxbai-embed-large. If you wish to utilize other models, you must create a custom config file and pass this to your server.
# LLM used for user-facing output, like RAG replies
quality_llm = "ollama/llama3.1"
# LLM used for ingesting visual inputs
vlm = "ollama/llama3.2-vision" # TODO - Replace with viable candidate
# LLM used for transcription
audio_lm = "ollama/llama3.1" # TODO - Replace with viable candidate
[embedding]
provider = "ollama"
base_model = "mxbai-embed-large"
base_dimension = 1_024
batch_size = 128
add_title_as_prefix = true
concurrent_request_limit = 2
[completion_embedding]
provider = "ollama"
base_model = "mxbai-embed-large"
base_dimension = 1_024
batch_size = 128
add_title_as_prefix = true
concurrent_request_limit = 2
[agent]
tools = ["local_search"]
[agent.generation_config]
model = "ollama/llama3.1"
[completion]
provider = "litellm"
concurrent_request_limit = 1
[completion.generation_config]
temperature = 0.1
top_p = 1
max_tokens_to_sample = 1_024
stream = false
```
We launch R2R by specifying this configuration file:
export R2R_CONFIG_NAME=ollama
python -m r2r.serve
Since we're serving with Docker, once R2R successfully launches the R2R dashboard opens for us. We can upload a document and see requests hit our Ollama server.
Retrieval and Search
Now that we have ingested our file, we can perform RAG and chunk search over it. Here, we see that we are able to get relevant results and correct answers—all without needing to make a request out to an external provider!
Extracting Entities and Relationships
If we'd like to build a graph for our document, we must first extract the entities and relationships that it contains. Through the dashboard we can select the 'Document Extraction' action in the documents table. This will start the extraction process in the background, which uses named entity recognition to find entities and relationships.
Note that this process can take quite a bit of time, depending on the size of your document and the hardware running your model. Once the process is complete,
we will see that the extraction status has turned green.
Graph RAG
Now we must pull the document extractions into the graph. This is done at the collection level, and creates a copy of our extractions for searching over and creating communities with.
Then, we can conduct search, RAG, or agent queries that utilize the graph.
Building communities
We can go one step further and create communities over the entities and relationships in the graph. By clustering over the closely related extractions, we can further develop the understanding of how these entities and relationships interact. This can be particularly helpful in sets of documents where we see overarching or recuring themes.
We trigger the extraction procedure, which produces a number of communities. Now, when we run queries over our graph we can utilize the communities to provide context that better encompasses overall concepts and ideas throughout our documents.