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).
68 lines
2.0 KiB
Python
68 lines
2.0 KiB
Python
import os
|
|
from enum import Enum
|
|
from typing import Any, Dict, List, Optional
|
|
|
|
from langchain_core.callbacks import CallbackManagerForRetrieverRun
|
|
from langchain_core.documents import Document
|
|
from langchain_core.retrievers import BaseRetriever
|
|
|
|
# Maximum characters of raw_content to embed per document.
|
|
# Large documents (e.g. scraped PDFs) can exceed embedding API token limits
|
|
# (e.g. OpenAI's 300 000 token-per-request cap) when all chunks are sent at once.
|
|
# Defaults to 50 000 chars (~12 500 tokens); override with MAX_CONTENT_CHARS env var.
|
|
_MAX_CONTENT_CHARS = int(os.environ.get("MAX_CONTENT_CHARS", 50000))
|
|
|
|
|
|
class SearchAPIRetriever(BaseRetriever):
|
|
"""Search API retriever."""
|
|
pages: List[Dict] = []
|
|
|
|
def _get_relevant_documents(
|
|
self, query: str, *, run_manager: CallbackManagerForRetrieverRun
|
|
) -> List[Document]:
|
|
|
|
docs = [
|
|
Document(
|
|
page_content=page.get("raw_content", "")[:_MAX_CONTENT_CHARS],
|
|
metadata={
|
|
"title": page.get("title", ""),
|
|
"source": page.get("url", ""),
|
|
},
|
|
)
|
|
for page in self.pages
|
|
]
|
|
|
|
return docs
|
|
|
|
class SectionRetriever(BaseRetriever):
|
|
"""
|
|
SectionRetriever:
|
|
This class is used to retrieve sections while avoiding redundant subtopics.
|
|
"""
|
|
sections: List[Dict] = []
|
|
"""
|
|
sections example:
|
|
[
|
|
{
|
|
"section_title": "Example Title",
|
|
"written_content": "Example content"
|
|
},
|
|
...
|
|
]
|
|
"""
|
|
|
|
def _get_relevant_documents(
|
|
self, query: str, *, run_manager: CallbackManagerForRetrieverRun
|
|
) -> List[Document]:
|
|
|
|
docs = [
|
|
Document(
|
|
page_content=page.get("written_content", ""),
|
|
metadata={
|
|
"section_title": page.get("section_title", ""),
|
|
},
|
|
)
|
|
for page in self.sections # Changed 'self.pages' to 'self.sections'
|
|
]
|
|
|
|
return docs |