- Local Lens: in-browser Knowledge Base libraries stored in OPFS/IndexedDB-style browser storage and queried from a worker.
- External Lens endpoint: an OpenAI-like search endpoint documented in Lens endpoint contract.
Core modules
Storage model
Local Lens persists user libraries inside browser storage, not getbased servers. Each library has:- an id and display name;
- selected embedding model metadata;
- source documents and extracted text;
- chunks with offsets and source attribution;
- embeddings for the selected model;
- lightweight search/index metadata.
Embedding model behavior
The worker supports a small model catalog, including MiniLM/BGE/E5-style options. The active library’s model controls how new chunks are embedded. Changing a model may require re-embedding the library because vector dimensions and embedding spaces are not interchangeable. WebGPU is preferred when available. WASM/CPU fallback remains functional and visibly cancellable. Model recommendation is intentionally conservative: a fast MiniLM benchmark on CPU recommends the balanced BGE-small profile, not BGE-base. BGE-base is automatically recommended only for a fast WebGPU path because MiniLM timing does not predict the larger model’s CPU cost.Chunking and retrieval
The local worker chunks source text, embeds each chunk in small bounded batches, then retrieves relevant passages for chat. Query rewriting and MMR-style diversity logic prevent every result from coming from the same paragraph when a document repeats the same phrase. Imports are transactional. A content fingerprint skips unchanged files, while changed content with the same source name replaces the previous excerpts. Stopping during embedding discards the pending vectors and leaves the current library intact. Persisted manifests created before fingerprints were added remain compatible; the next re-import indexes that document once and records its fingerprint. When implementing retrieval changes, preserve:- source title and filename attribution;
- chunk offsets or enough metadata to reopen the source context;
- abortability during long imports;
- transactional safety if the user closes the modal or stops indexing;
Difference from external Lens
Do not document an external endpoint behavior as if it applies to local Lens. The external contract is only the wire protocol for a configured remote RAG server.
Verification checklist
Before shipping local Lens changes:- run worker/runtime unit tests for ingest, query, delete, abort, and model switching;
- run browser specs for library creation and active-library selection;
- verify large imports can be cancelled without corrupting the library;
- verify source attribution appears in chat grounding;
- verify clearing/deleting a library removes its chunks and embeddings;
- test WebGPU-unavailable fallback when the change touches model loading.