The schema layer provides authoritative, versioned snapshots and structured retrieval to ground planning. It is split into:
Schema contracts are defined in nl2sql_adapter_sdk.schema:
SchemaContract: datasource_id, engine_type, tablesTableContract: table ref, column contracts, foreign keysColumnContract: name, type, nullability, primary key flagForeignKeyContract: constrained/referred columns, cardinality, business meaningMetadata complements contracts:
SchemaMetadata: datasource description/domains, table metadataTableMetadata: table description, row_count, column metadataColumnMetadata: description, stats, synonyms, PII flagColumnStatistics: distinct counts, min/max, sample valuesEach SchemaSnapshot (contract + metadata) is versioned using a deterministic fingerprint:
build_schema_store() constructs a store based on settings:
InMemorySchemaStore: in-memory, versioned snapshots.SqliteSchemaStore: persistent storage with indexes on fingerprint and timestamps.Schema versions are timestamped and include a fingerprint prefix (e.g., YYYYMMDDhhmmss_<fp8>). Old versions are evicted beyond schema_store_max_versions.
Schema retrieval resolves authoritative tables/columns from SchemaStore, not from the vector store. Vector store chunks are only used to identify candidates; final schema is resolved via snapshot. If retrieval yields no candidates, the retriever falls back to the full snapshot. schema_version_mismatch_policy governs mismatches between chunk versions and store versions.
See ../architecture/indexing.md for retrieval stages, chunk types, and vector store behavior.
packages/adapter-sdk/src/nl2sql_adapter_sdk/schema.pypackages/core/src/nl2sql/schema/protocol.pypackages/core/src/nl2sql/schema/store.pypackages/core/src/nl2sql/schema/sqlite_store.pypackages/core/src/nl2sql/pipeline/nodes/schema_retriever/node.py