Repository navigation
Extending Retriever and Embedder
A
Retrieverpicks the seed tables for a question; anEmbedderturns text into vectors for the embedding retriever. Any object withsearch(question, k) -> [(table ref, score), ...]is a retriever, and any object with amodel_idandembed(texts)is an embedder. Combine retrievers withHybridRetriever(reciprocal-rank fusion) and pass the result to the Guru.
class Retriever(Protocol):
def search(self, question: str, k: int) -> list[tuple[ObjectRef, float]]: ...
class Embedder(Protocol):
@property
def model_id(self) -> str: ... # names model + version
def embed(self, texts: Sequence[str]) -> list[list[float]]: ...A retriever returns table refs, higher score better, ordered by score and then by canonical name (determinism: the same store and question must give the same list). Search inside the store or an index; never scan every table in Python, which does not scale.
class HashingEmbedder:
"""A toy embedder (bag of hashed words); replace with a real model client."""
model_id = "hashing-v1" # vectors from different ids are never mixed
def embed(self, texts):
out = []
for text in texts:
v = [0.0] * 64
for w in text.lower().split():
v[int(hashlib.sha256(w.encode()).hexdigest(), 16) % 64] += 1.0
out.append(v)
return outfrom schemaguru.scope import EmbeddingRetriever, HybridRetriever, LexicalRetriever
emb = EmbeddingRetriever(guru.store, HashingEmbedder()) # extra: schemaguru[embeddings] (numpy)
emb.index() # embeds changed table documents; returns a count
guru.retriever = HybridRetriever(LexicalRetriever(guru.store), emb)
guru.retriever.search("customer segment", 3)Real output on the measured shop fixture (2026-11-24): emb.index() returned 14, and the search
returned customers (0.0328), orders (0.0320), events (0.0161). Vectors are stored per
(model_id, table) with a hash of the table document, so index() re-embeds only tables whose
document changed, and vectors from different model_ids are never mixed. Assign the retriever
before the first context() call (cached views are not invalidated by the assignment), or pass
retriever= to sg.Guru(...).
def test_retriever_is_deterministic(guru):
r = HybridRetriever(LexicalRetriever(guru.store), emb)
assert r.search("customer segment", 5) == r.search("customer segment", 5)
def test_negative_control_empty_question_finds_nothing_useful(guru):
assert all(score >= 0 for _, score in emb.search("", 3))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