You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add an opinionated local semantic knowledge library for QuantMind's typed financial knowledge.
The public surface is deliberately small:
LocalKnowledgeLibrary
SemanticQuery
SemanticHit
It persists canonical BaseKnowledge, indexes both knowledge items and tree nodes, performs financial-time-aware semantic search, and returns QuantMind evidence with source and citation metadata.
This is the first retrieval priority. It establishes the semantic baseline before PageIndex-style agentic navigation in #95.
Motivation
QuantMind defines embedding_text() on knowledge items and tree nodes, but it does not provide embedding generation, a durable semantic index, or a semantic query API.
A semantic baseline has broader demand than long-document navigation:
It works across flat cards, whole documents, and tree nodes.
It provides fast cross-document candidate retrieval.
It provides one stable financial-domain API for agent tools and examples.
QuantMind must not become another generic RAG framework. The differentiating work is mapping typed financial knowledge to auditable search evidence, not provider registries, vector database abstractions, or answer generation.
knowledge/ defines immutable canonical schemas and remains free of I/O.
library/ persists, indexes, and searches canonical knowledge collections.
mind/ consumes the library through agent tools; the library never depends on mind.
flows/ may write extracted results into the library.
preprocess/ remains independent and does not become a storage service.
Update import-linter so library may depend on knowledge and low-level external libraries, but not on mind, flows, magic, or preprocess.
Private provider/backend seams are allowed only when they isolate external side effects or enable deterministic tests. A helper that only forwards a call must be inlined.
Canonical and derived data
Canonical knowledge is the source of truth.
Embeddings and searchable records are derived and rebuildable, even when stored in the same SQLite file.
Raw PDF, HTML, and media retention is caller-owned and outside V1.
FlattenKnowledge: one searchable record from embedding_text().
TreeKnowledge: one document/root record plus one record per non-root TreeNode; the item record represents the root once with node_id=None.
Stable target identity distinguishes an item from one of its nodes.
Index metadata records model, dimensions, projection hash, source content hash, and schema version.
Re-putting unchanged knowledge is idempotent and does not call the embedding provider again. This guarantee is scoped to the same canonical item ID; cross-extraction deduplication needs a separate stable-ID contract.
Changed projection/model/schema metadata invalidates only affected vectors.
V1 uses one private local implementation. SQLite plus exact cosine ranking with the existing NumPy dependency is sufficient. Do not expose a backend contract before a second real backend exists.
Financial time semantics
BaseKnowledge.as_of is the information cutoff represented by an item, not necessarily the time the source became observable. Add optional BaseKnowledge.available_at and keep the query filters distinct:
as_of_before: information-cutoff filtering;
available_at_before: source-availability filtering for no-look-ahead research.
Flows should populate available_at from source publication time. If only fetch time is known, SourceRef.fetched_at is a conservative upper bound. When available_at_before is provided, records with unknown availability are excluded rather than assumed safe.
Provider- or database-specific response types must not leak through the public API. matched_text is the exact projection used for ranking; get(item_id) returns the validated canonical BaseKnowledge so callers can resolve node IDs, paths, and full content. delete(item_id) transactionally removes the canonical item and all derived root/node records.
Non-goals
Public Embedder, VectorStore, Retriever, or backend frameworks
Backend registry or multiple vector-database adapters
Feature Summary
Add an opinionated local semantic knowledge library for QuantMind's typed financial knowledge.
The public surface is deliberately small:
LocalKnowledgeLibrarySemanticQuerySemanticHitIt persists canonical
BaseKnowledge, indexes both knowledge items and tree nodes, performs financial-time-aware semantic search, and returns QuantMind evidence with source and citation metadata.This is the first retrieval priority. It establishes the semantic baseline before PageIndex-style agentic navigation in #95.
Motivation
QuantMind defines
embedding_text()on knowledge items and tree nodes, but it does not provide embedding generation, a durable semantic index, or a semantic query API.A semantic baseline has broader demand than long-document navigation:
QuantMind must not become another generic RAG framework. The differentiating work is mapping typed financial knowledge to auditable search evidence, not provider registries, vector database abstractions, or answer generation.
Scope
Package boundary
Introduce a top-level
quantmind/library/package:Layer semantics:
knowledge/defines immutable canonical schemas and remains free of I/O.library/persists, indexes, and searches canonical knowledge collections.mind/consumes the library through agent tools; the library never depends onmind.flows/may write extracted results into the library.preprocess/remains independent and does not become a storage service.Update import-linter so
librarymay depend onknowledgeand low-level external libraries, but not onmind,flows,magic, orpreprocess.Private provider/backend seams are allowed only when they isolate external side effects or enable deterministic tests. A helper that only forwards a call must be inlined.
Canonical and derived data
FlattenKnowledge: one searchable record fromembedding_text().TreeKnowledge: one document/root record plus one record per non-rootTreeNode; the item record represents the root once withnode_id=None.V1 uses one private local implementation. SQLite plus exact cosine ranking with the existing NumPy dependency is sufficient. Do not expose a backend contract before a second real backend exists.
Financial time semantics
BaseKnowledge.as_ofis the information cutoff represented by an item, not necessarily the time the source became observable. Add optionalBaseKnowledge.available_atand keep the query filters distinct:as_of_before: information-cutoff filtering;available_at_before: source-availability filtering for no-look-ahead research.Flows should populate
available_atfrom source publication time. If only fetch time is known,SourceRef.fetched_atis a conservative upper bound. Whenavailable_at_beforeis provided, records with unknown availability are excluded rather than assumed safe.Other V1 filters are limited to canonical fields:
item_typessource_kindsconfidencetagstree_idtop_kProposed API
A
SemanticHitcarries:Provider- or database-specific response types must not leak through the public API.
matched_textis the exact projection used for ranking;get(item_id)returns the validated canonicalBaseKnowledgeso callers can resolve node IDs, paths, and full content.delete(item_id)transactionally removes the canonical item and all derived root/node records.Non-goals
Embedder,VectorStore,Retriever, or backend frameworksDocument + metadata: dictAPIsAcceptance Criteria
get()resolves item/node evidence from canonical knowledge.as_of_beforeandavailable_at_beforehave distinct tested semantics.as_ofalone prevents look-ahead.get()anddelete()have explicit not-found and stale-data behavior.tests/library/and inheritunittest.TestCaseorunittest.IsolatedAsyncioTestCase.examples/library/.scripts/verify.shpasses.Related Issues
Implementation Considerations
Breaking Changes
available_atis additive and optional.Dependencies