Skip to content

The system at a glance ​

This page shows the parts of Scholar Lens and how a question becomes a cited answer. It is for developers who want to change the code. Each part has its own page, linked below.

The parts ​

Figure 1 shows the processes and what they talk to. Everything runs on one machine; nothing leaves it except web searches and page fetches.

flowchart LR
  subgraph Browser
    UI[React app]
    EXT[Browser extension]
  end
  subgraph Server
    API[FastAPI API<br/>answer graph, run pool]
    W[Job worker<br/>indexing, imports, summaries]
    PG[(Postgres + pgvector)]
  end
  subgraph Models
    LMS[LM Studio<br/>chat + embedding]
    RR[llama.cpp<br/>reranker]
  end
  subgraph Optional
    SB[Code sandbox<br/>gVisor]
    WEB[Tavily / SearXNG<br/>OpenAlex / arXiv]
    BR[Playwright MCP<br/>browser]
    SI[Sign-in browser]
  end
  UI -- HTTP + SSE --> API
  EXT -- token --> API
  API --> PG
  W --> PG
  API --> LMS
  W --> LMS
  API --> RR
  API --> SB
  API --> WEB
  API --> BR
  API --> SI

Figure 1. Processes and their connections. The worker can also run inside the API process.

PartTechnologyPage
Web appReact 19, TypeScript, Vite, Tailwind, TanStack Query, ZustandFrontend
APIFastAPI, SQLAlchemy, AlembicBackend and API
Answer graphLangGraph, with a Postgres checkpointerThe answer graph
Ingestionpymupdf4llm, RapidOCR, python-docx, trafilaturaIngestion
Retrievalpgvector, Postgres full text, a cross-encoder rerankerRetrieval and reranking
EvidenceCode, not the model: citations, quote checks, confidenceEvidence and citations
Web researchTavily, SearXNG, OpenAlex, arXiv, Playwright over MCPWeb research and sign-in
Code sandboxJupyter kernels in a gVisor containerThe code sandbox
RunsA bounded pool, durable runs, an event log for live view and replayRuns, events and replay
StorageOne Postgres database for everythingData model
AccessCookies with short-lived JWTs, roles, Space sharingSecurity and access
ExtensionManifest V3, TypeScriptBrowser extension

From a question to an answer ​

  1. The browser posts the message to POST /api/threads/{id}/messages. The API stores it and creates an execution (a run).
  2. The run pool starts the run, or queues it when two are already running.
  3. The run executes the answer graph: plan, retrieve (and search the web when needed), check coverage, pack the evidence, draft, verify the claims, revise if needed, and finalise. The graph saves its state after every step, so a run cut off by a restart resumes.
  4. Every step writes run events to the database: step started and finished, passages found, tokens of the draft as they stream. The browser follows them over server-sent events (SSE).
  5. The final answer, its citations, confidence and mind map are saved as an assistant message.

The model writes only the answer text and short structured replies. Page numbers, titles, links and the confidence label come from code and the index. This is what makes the citations trustworthy.

From an upload to the index ​

  1. POST /api/library/upload saves the file and queues an index_document job.
  2. The worker claims the job, parses the file in a child process, builds the section tree, chunks the text per section and embeds the chunks.
  3. It replaces the document's chunks in one transaction, so a failed re-index never leaves a document empty.
  4. It queues section-summary jobs at background priority.

Design rules ​

These run through the whole code base.

  • Local first. The models run on the user's GPU. Web search is opt-in per Space.
  • Facts from code, words from the model. Citations, page numbers and confidence are computed, never generated.
  • Abstain rather than guess. With no relevant evidence the graph declines instead of drafting.
  • Everything durable is in Postgres. Jobs, runs, checkpoints, events and vectors share one database, so one backup holds everything.
  • Private by default. A user's Library, chats and notes are theirs. Sharing is explicit.