Core Architecture.
Local Ingestion Pipeline
PDFs are parsed entirely client-side using deterministic PDF.js streams. We extract raw text, identify header structures, and cleanly separate reference blocks from core methodology text without ever sending raw files over the wire.
Vector Embedding
Parsed text is chunked into 500-token blocks with a 50-token semantic overlap. We use Transformers.js to generate dense embedding vectors (e.g., Xenova/all-MiniLM-L6-v2) directly inside the browser using WebAssembly.
Semantic Synthesis (RAG)
When a user queries the intelligence module, the query is embedded locally. We perform a cosine similarity search across the local IndexedDB vector store. The top-K mathematically relevant chunks are retrieved and packed into a deterministic prompt payload, which is then fed into the LLM (Google Gemini or OpenAI) for final synthesis.
const contextPayload = topChunks.map(c => ` [Paper: ${c.metadata.title}, Page: ${c.metadata.page}] ${c.text}`).join('\\n---\\n');