Repository navigation
Extending Store
A
Storeis where knowledge lives; SQLite is the default andPostgresStorethe shared backend. Any object implementing theschemaguru.store.protocol.Storeprotocol can be passed assg.Guru(store=...). Writing a new backend is the largest extension point, so the advice here is to reuse the SQLite store's behaviour as the reference and test against the same expectations.
schemaguru.store.protocol.Store covers (all writes are idempotent upserts keyed on stable ids):
| Group | Methods |
|---|---|
| structure |
upsert_schemas, upsert_tables, upsert_columns, upsert_constraints, mark_withdrawn, table, columns, constraints, iter_schemas, iter_tables(include_withdrawn=False)
|
| names |
resolve(text) -> (ref, candidates), tables_named(names, limit=...)
|
| facts |
put_facts, delete_facts, iter_facts, facts_for(subjects, kinds)
|
| search |
search(query, k) (lexical, live tables, name hits first) |
| snapshots |
snapshot(label, checks_run=...), snapshot_facts, snapshot_checks_run, latest_snapshot
|
| state |
crawl_state_get, crawl_state_set, ledger_add, ledger_total, queue_push, queue_pop, feedback_add, feedback_summary
|
| transactions |
transaction() (a context manager) |
The contracts that matter most (each one is relied on elsewhere):
-
iter_tablesstreams in canonical-ref order and never loads the whole catalog. -
upsert_columns/upsert_constraintsmake the given list the table's complete list. -
mark_withdrawnis a soft delete that keeps an earlierwithdrawn_atand touches no facts. -
resolve: exact first, then a unique case-insensitive match; ambiguous returns(None, candidates); never a guess. -
facts_for(None, ...)means no filter; an empty iterable matches nothing; results sorted by id. -
put_factsupserts byFact.id(re-measurement replaces);delete_facts(ids)removes live facts (snapshots keep their copies) and returns how many existed. -
searchmust run in an index, not as a Python scan (it is on the agent's hot path). - Optional, for the embedding retriever:
embeddings_put,embeddings_get,embeddings_hashes.
The cheapest custom store is a wrapper that adds behaviour around SQLiteStore, for example
logging every fact write:
from schemaguru.store.sqlite import SQLiteStore
class LoggingStore:
def __init__(self, path):
self._inner = SQLiteStore(path)
def put_facts(self, facts):
facts = list(facts)
print(f"writing {len(facts)} facts")
self._inner.put_facts(facts)
def __getattr__(self, name): # everything else: delegate
return getattr(self._inner, name)
guru = sg.Guru(store=LoggingStore("shop.db"), reader=reader, dialect="duckdb")A store you pass in is not closed by guru.close(); close it yourself.
The repository has a backend-agnostic contract suite,
tests/unit/store/contract.py:
every function in it is a test taking a store fixture, and both shipped stores pass it. Run it
against yours:
# tests/test_my_store.py
import pytest
from tests.unit.store.contract import * # noqa: F403 (the contract tests)
@pytest.fixture
def store(tmp_path):
s = MyStore(tmp_path / "s.db")
yield s
s.close()Two of the contracts, written out as a starting point for backend-specific tests:
def test_resolve_never_guesses(store):
store.upsert_schemas([Schema(None, "shop")])
store.upsert_tables([Table(sg.ObjectRef(None, "shop", "Orders"), "table"),
Table(sg.ObjectRef(None, "shop", "ORDERS"), "table")])
ref, cands = store.resolve("shop.orders")
assert ref is None and len(cands) == 2 # ambiguous: candidates, no guess
def test_put_facts_is_idempotent(store, fact):
store.put_facts([fact]); store.put_facts([fact])
assert store.facts_for([fact.subject], [fact.kind.name]) == [fact]- Store
- Server - replicas sharing a Postgres store
- Extending-Retriever-and-Embedder
- Architecture
SchemaGuru is open source under the MIT License, Copyright (c) 2026 Rupak Chakraborty · Repository · Issues · This wiki is generated from docs/wiki/; edit it there, not here.
Start here
Components
- Catalog and Crawl
- Store
- Measurement
- Sampling
- Join Graph
- Path Search and Hub Guard
- Waypoint Rules
- Drafting
- PII and Sampling Policy
- Overlays
- Scoping
- Rendering
- Refresh and Drift
- Feedback and Guard
- Server
- Agent Integration
Using it
Warehouses
- BigQuery
- Snowflake
- Redshift
- Databricks
- PostgreSQL
- DuckDB
- ClickHouse
- SQL Server / Synapse
- Oracle
- Trino
- MySQL / MariaDB
Extending
- CatalogReader
- Store
- Retriever and Embedder
- TokenCounter
- LLMProvider
- PII Detector
- FailureClassifier
- FactKind
- Profile and Format
- ChangeClassifier
- JoinCandidateSource (planned)
- Authenticator
Project