Repository navigation
RAG & Local AI Assistant
Biotechnology discovery and biopharma patents involve highly confidential, proprietary intellectual property. Sending unreleased construct sequences, experimental notes, or novel purification protocols to public cloud LLM endpoints (e.g. OpenAI, Anthropic) introduces significant data-leakage and compliance risks.
The BioLabCalc Retrieval-Augmented Generation (RAG) and Local AI Assistant subsystem (biolabcalc.eln.rag) provides an air-gapped, zero-data-leakage intelligence layer that runs entirely on local workstation hardware or institutional GPU clusters. It combines protocol-aware semantic chunking, dense-sparse hybrid retrieval with Reciprocal Rank Fusion (RRF), and offline local language models.
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Laboratory Query β
β "What was the optimal imidazole concentration and elution volume for T7RNAP?" β
βββββββββββββββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Hybrid Retrieval Engine (`hybrid_search.py`) β
β ββββββββββββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββ β
β β Dense Semantic Search β Sparse Lexical Search (BM25) β β
β β β’ 1536-dim vector embeddings β β’ Token frequency inverted index β β
β β β’ Cosine similarity scoring β β’ Biological entity boost (constructs, β β
β β β’ Understands biophysical synonyms β columns, resins, mutations) β β
β βββββββββββββββββββββ¬βββββββββββββββββββββ΄βββββββββββββββββββββ¬βββββββββββββββββββββ β
β β β β
β ββββββββββββββββββββββ¬βββββββββββββββββββββ β
β β β
β βΌ β
β Reciprocal Rank Fusion (RRF Scoring) β
β RRF(d) = 1/(60 + r_dense) + 1/(60 + r_sparse) β
β β β
β βΌ β
β Multi-User Temporal & Provenance Filters β
β (Filter by project, author, alumni status, date) β
βββββββββββββββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββ
β Top-K Ranked Laboratory Chunks
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Contextual Citation Synthesizer (`synthesizer.py`) β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Assembles structured prompt with laboratory provenance blocks: β β
β β [Ref 1] Author: Dr. Rosalind Franklin | Campaign: CMP-2026-T7 | Day 4 β β
β β Instrument: ΓKTA pure 25 | File: /runs/t7rnap_histrap_04.res β β
β β "Elution occurred at 250 mM imidazole with peak UV280 at Ve = 14.5 mL" β β
β ββββββββββββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Local Inference Client (`local_llm.py`) β
β ββββββββββββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββ β
β β On-Premise GPU / Cluster Endpoints β Air-Gapped Offline Fallback Engine β β
β β β’ Ollama (Llama 3, Mistral, Qwen) β β’ Deterministic n-gram hypersphere β β
β β β’ vLLM / OpenClaw / LocalAI (GGUF) β pseudo-embedding generator β β
β β β’ SLURM head-node HTTP inference β β’ Rule-based biochemical reasoning β β
β β β’ Zero cloud API calls or data escape β β’ 100% test reliability with no network β β
β ββββββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Synthesized Lab Output β
β Authoritative answer with exact provenance citations [Ref 1], stoichiometric checks, β
β and direct links to underlying notebook entries and FPLC fractions. β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Generic text chunkers split documents at arbitrary token counts (e.g. 500 tokens), frequently severing multi-line reaction recipes, splitting pipetting tables, or separating centrifuge parameters from their steps.
BioLabCalc implements a Domain-Specific Laboratory Chunker:
- Structural Boundary Respect: Chunks respect Markdown headings, numbered protocol steps, and delimiter blocks.
- Table Preservation: Multi-column reagent recipes and plate maps are preserved as intact units.
-
Biological Entity Extraction (
LaboratoryEntityExtractor): Ingestion automatically extracts normalized scientific entities into metadata tags:-
Constructs & Plasmids:
pET-28a,pGEX-6P-1,pUC19,pBAD. -
Chromatography Resins & Columns:
HisTrap HP 5 mL,Superdex 200 Increase 10/300 GL,Mono Q. -
Reagents & Buffers:
50 mM Tris-HCl,500 mM Imidazole,1 mM DTT,10X PBS. -
Quantitative Metrics: Elution volumes (
$V_e = 14.5\text{ mL}$ ), total yields ($19.25\text{ mg}$ ), and purity ($94.2%$ ).
-
Constructs & Plasmids:
-
Comprehensive Provenance Tags (
ProvenanceMetadata): Each chunk retains the author ID, author name, project tag, campaign ID, day number, instrument run ID, and file path.
Pure dense vector search frequently fails on exact scientific identifiers (such as catalog numbers, plasmid names like pET-28a-T7-K12A, or buffer concentrations). Pure lexical search (BM25) fails when the user asks conceptual or biophysical questions ("How do I prevent column fouling during cell lysis?").
BioLabCalc resolves this via Dense-Sparse Hybrid Retrieval with Reciprocal Rank Fusion:
where
- Lexical Inverted Index (BM25): Matches exact keywords, primer sequences, and catalog codes with term-frequency saturation.
- Dense Vector Indexing: Evaluates conceptual similarity using 1536-dimensional embeddings.
- Biological Entity Boost: Chunks containing exact matches for detected constructs or enzymes receive an automated score boost.
- Alumni & Temporal Provenance Filtering: Enables filtering queries to active researchers vs. historical alumni records (e.g., retrieving only protocols validated within the last 12 months).
The local inference client provides zero-dependency connectivity to local open-weights language models:
from biolabcalc.eln.rag.local_llm import LocalLLMClient
# Connect to local Ollama server running Llama-3 or Mistral
client = LocalLLMClient(
base_url="http://localhost:11434",
model_name="llama3:latest",
)
response = client.generate(
prompt="Summarize the lysis buffer composition for Campaign CMP-2026-T7.",
system="You are an expert bioprocess laboratory assistant. Cite all references.",
)-
Ollama: Default local desktop and workstation server (
http://localhost:11434). - vLLM / OpenClaw / LocalAI: High-throughput GPU inference servers running quantized GGUF, AWQ, or FP16 models.
- HPC / SLURM Head-Nodes: Direct HTTP endpoint forwarding to institutional supercomputing clusters.
When running on minimal machines without GPU hardware or network access to an Ollama server, the client automatically falls back to:
-
OfflineEmbeddingGenerator: A deterministic hashing engine that maps text n-grams and scientific tokens to a unit hypersphere vector space, enabling full unit testing and basic vector search without PyTorch or CUDA. -
OfflineHeuristicGenerator: A rule-based biochemical reasoning engine that extracts metrics ($V_e$ , yields, buffers) from retrieved context blocks and formats authoritative responses citing[Ref 1],[Ref 2].
The ContextualSynthesizer coordinates the complete RAG loop, generating answers with verifiable citation footnotes.
- Query: "What was the optimal wash volume and imidazole concentration used for the HisTrap step in Campaign 001?"
-
Response: Summarizes the 10 column-volume (CV) wash at 25 mM imidazole and elution at 250 mM imidazole, appending a direct reference link to
[Ref 1](Day 4 Notebook Entry by Alice).
- Query: "Why did the Day 3 induction yield drop to 2.1 mg/L culture in the GFP campaign?"
- Response: Analyzes the kinetic timepoint logs and notes that the incubator temperature drifted to 41.2Β°C for 45 minutes due to a sensor malfunction, leading to inclusion body formation.
- Query: "Check the calculations for scaling the lysis buffer from 500 mL to 4 Liters."
-
Response: Cross-references
biolabcalc.buffersand validates that Tris-HCl, NaCl, and Triton X-100 quantities scale linearly while warning that DTT must be added fresh immediately prior to lysis.
- Electronic Lab Notebook (ELN) β Launching the global RAG modal via the web UI (βK).
- Instrument Data Parsers β How analytical outputs are extracted for vector indexing.
- GxP Compliance & Audit Trails β Audit logging for AI-assisted protocol adjustments.
BioLabCalc Documentation Wiki | Licensed under the MIT License | GitHub Repository Research Use Only (RUO). Not intended for clinical or diagnostic procedures.
- Core Calculators & Stoichiometry
- Solution Prep & Spectroscopy
- Buffers & Precipitation
- Protein Quantification & Assays
- Fluorophores & Dye Labeling
- Molecular Cloning & Assembly
- Plasmid Engineering & Workbench
- PCR Kinetics & Primer Design
- In Vitro Transcription (IVT)
- Western Blotting Suite
- Bacterial Growth & Kinetics
- ELN System Architecture
- SOP & Protocol Management
- Instrument Data Parsers
- Inventory & Freezer LIMS
- Local RAG Knowledge Engine
- GxP Compliance & Audit Trails