Skip to content

Data model ​

Scholar Lens keeps everything in one Postgres database with the pgvector extension: accounts, the Library and its vectors, Spaces, chats, runs and their events, jobs, study material and settings. This page lists the tables and how they relate. The models are in app/db/models.py and app/db/study.py; the migrations in app/db/migrations/versions/.

The main tables ​

Figure 1 shows the core of the schema.

erDiagram
  users ||--o{ documents : owns
  users ||--o{ spaces : owns
  spaces ||--o{ space_sources : has
  documents ||--o{ space_sources : "used by"
  spaces ||--o{ space_members : "shared with"
  users ||--o{ space_members : joins
  documents ||--o{ doc_nodes : "section tree"
  documents ||--o{ chunks : "indexed as"
  doc_nodes ||--o{ chunks : contains
  spaces ||--o{ sessions : "chats in"
  sessions ||--o{ messages : holds
  sessions ||--o{ executions : runs
  executions ||--o{ execution_events : logs
  sessions ||--o{ session_files : attaches
  session_files ||--o{ chunks : "indexed as"
  sessions ||--o{ code_cells : runs

Figure 1. The core tables. Study, memory, access and admin tables are listed below.

Accounts and access ​

TableWhat it holds
usersUsername, argon2id password hash, role (admin or user), active, pending approval, must change password, preferences
auth_sessionsOne row per signed-in browser: the hashed refresh token, user agent, IP, expiry, revocation
api_tokensPersonal access tokens for the extension: name, SHA-256 hash, prefix, last used, revoked
invitesSpace invite links: hashed token, role, expiry
space_membersWho a Space is shared with, as editor or viewer
access_grantsSealed cookies from the sign-in browser, per student, Space and site
audit_logSecurity-relevant actions: sign-ins, token creation, admin access to content, publishing

Library ​

TableWhat it holds
documentsA Library item: kind (file, url, youtube, arxiv, doi, page), title, authors, year, bibliographic fields (bib), table of contents, page labels, file path and hash, status, chunk count, index_version, embedding model, shared flag
doc_nodesThe section tree: number, title, level, pages, parent, and the section summary with its embedding
document_linksAn item brought in from a saved page (reference, file, web page, video) and the page; searched with the page
duplicate_pairsA new Library item that looks like one already there: the two items, score, basis (file, DOI, title, content...), a few lines on how they differ, and the decision (open, kept, or replace once indexed)
chunksSearchable text: the owner, the document or session file it belongs to, its section node, scope (library, session, note), index version, page, section path, text, halfvec embedding and generated tsvector
publish_requestsA user's request to put an item in the shared Library, with notes and the admin's decision

A document's status is processing, ready, failed or reference (a citation with no text, from the extension). Only chunks with the document's current index_version are searched.

Indexes: HNSW (halfvec_cosine_ops) on chunks.embedding, GIN on chunks.tsv.

Spaces and chats ​

TableWhat it holds
spacesTitle, icon, instructions, default style, web policy (off, auto, always), code policy (off, ask, auto)
space_sourcesA document in a Space: its scope (the label as typed, the sections and the page ranges it resolved to), role, pinned
sessionsA chat in a Space, with the message its current branch ends at (active_message_id)
messagesUser and assistant messages. parent_id makes them a tree, so edits and "ask again" are branches. An answer's citations, confidence and mind map are in its payload.
session_filesFiles attached to one chat
memory_itemsMemory about the user or a Space, pinned by the student or proposed by the agent and accepted

Runs and jobs ​

TableWhat it holds
executionsA run: status, idempotency key, heartbeat, times, cancel flag, resume count, per-run options
execution_eventsThe run's numbered event log, for the live view and replay
checkpoints, checkpoint_blobs, checkpoint_writes, checkpoint_migrationsLangGraph's own tables for durable runs. LangGraph creates and migrates them; Alembic leaves them alone.
jobsBackground jobs: kind, status, priority, attempts, run-after time, progress
code_cellsCode run in a chat: source, origin (answer or student), status, output streams, plots and files, error, duration, linked run

Web ​

TableWhat it holds
web_cacheSearch results per provider and query, for a day
web_pagesFetched pages and their outcome (including refusals), for a week
usageTavily credits per user per month

Study ​

TableWhat it holds
study_setsA flashcard set, quiz, glossary or concept map, with its scope and status
study_itemsCards, questions, terms, concepts and links, each with its citation and quote check
quiz_attemptsA student's answers and marks
notesHighlights and notes on a document page, with their position. Each note is also a chunks row with scope note, so answers can find it.

Settings and metadata ​

TableWhat it holds
app_settingsSettings saved by an admin. Secrets are encrypted.
app_metaA key-value table from the baseline schema, kept for small facts about the installation. Unused today.

Conventions ​

  • Primary keys are UUID strings, except log tables with big-integer ids.
  • Times are stored with time zones, in UTC.
  • Deleting a user, Space, document or chat cascades to what belongs to it.
  • Every schema change is a hand-written Alembic migration. A test (alembic check) fails if the models and the migrations disagree.
  • The embedding size is fixed when the database is created (EMBEDDING_DIMENSIONS).