This file guides AI agents operating in this repository. Follow these engineering constraints, architectural invariants, and command workflows strictly.
Strata is a 100% offline, air-gapped personal knowledge base and hybrid RAG engine.
- SQLite is the Canonical Source of Truth:
- Raw text, document metadata, chunk records, heading hierarchies, and SHA-256 hashes live exclusively in SQLite.
- Qdrant and BM25 are derived search indices. Never write directly to Qdrant without a corresponding record in SQLite.
- If Qdrant is wiped, running
strata syncmust deterministically reconstruct the entire vector index from SQLite.
- Content-Addressable Differential Invalidation:
- Never re-embed an entire document on update.
- Chunks are hashed via SHA-256 (
doc_id + heading_path + text). - Compare active hashes in SQLite with new hashes. Only embed newly added chunk hashes. Purge orphaned hashes from SQLite and Qdrant. Skip unchanged chunks completely.
- 100% Offline / Air-Gapped:
- Zero external API calls (no OpenAI, Anthropic, or external telemetry).
- Dense embeddings (
bge-small-en-v1.5) and re-ranking (bge-reranker-base) run via local tokenizers/runtimes (fastembedorsentence-transformers). - Generative synthesis runs through local Ollama endpoints (
http://localhost:11434).
- Decoupled Search vs. LLM:
- The core search engine (
strata search) must never initialize or call an LLM. It returns raw, rankedRetrievedChunkdataclasses/models in sub-200ms. - The LLM is strictly used for synthesis (
strata ask), evaluation judges (strata benchmark), or future agent reasoning loops.
- The core search engine (
- Language: Python 3.12+ (strictly typed)
- Package & Env Manager:
uv - Canonical DB: SQLite via
sqlite3 - Vector Store:
qdrant-clientin embedded local mode (QdrantClient(path="./data/qdrant")) - Sparse Index:
rank-bm25 - Local Embeddings & Reranking:
fastembed/sentence-transformers(BAAI/bge-small-en-v1.5,BAAI/bge-reranker-base) - Local LLM Engine: Ollama (
qwen3.5:0.8b) viaollama-pythonor OpenAI-compatible client - Evaluation:
ragaswith local Ollama judge - CLI:
typer[all]withrichformatting - Code Quality:
ruff(linter/formatter),mypy(strict mode),pytest
- 100% type annotations on all function signatures and class definitions.
- Avoid
Any. Use explicit generics,TypeVar, orProtocol. - Must pass
mypy --strictwith zero warnings. - All domain entities exchanged across module boundaries must be immutable or validated Pydantic v2
BaseModelinstances.
Define interfaces in src/strata/core/protocols.py using typing.Protocol. Concrete implementations in storage/ or retrieval/ must conform to these protocols without rigid class inheritance:
from typing import Protocol
from strata.core.models import Chunk, RetrievedContext
class VectorStore(Protocol):
def upsert_chunks(self, chunks: list[Chunk], embeddings: list[list[float]]) -> None: ...
def delete_by_document_id(self, document_id: str) -> None: ...
def delete_by_chunk_hashes(self, chunk_hashes: list[str]) -> None: ...
def search(
self, query_vector: list[float], limit: int, payload_filter: dict | None = None
) -> list[RetrievedContext]: ...- Never use raw
print()statements outside of the Typer presentation layer insrc/strata/cli/. - Use Python's standard
loggingmodule orloguruwith structured contextual key-values. - Handle database locks, missing files, and embedding timeouts gracefully with explicit custom domain exceptions (
DocumentNotFoundError,SyncConflictError,ModelInferenceError).
When running tasks or validating code changes, use uv run:
uv venv
source .venv/bin/activate
uv pip install -e ".[dev,eval]"Run these before completing any multi-step task:
# 1. Format and lint checks
uv run ruff check src/ tests/
uv run ruff format --check src/ tests/
# 2. Strict static typing
uv run mypy --strict src/
# 3. Unit and integration test suite
uv run pytest -v tests/# Ingest and sync notes
uv run strata add ./notes/example.md --tag test
uv run strata sync
# Fast search (No LLM, sub-200ms)
uv run strata search "query phrase" --top-k 3
# Synthesize answer with local Ollama
uv run strata ask "query phrase" --stream
# Run RAGAS benchmark
uv run strata benchmark --dataset tests/eval/golden_dataset.jsonWhen modifying or generating code:
- ❌ DO NOT import cloud LLM SDKs (
openai,anthropic,cohere) or make external network calls. - ❌ DO NOT store full document bodies inside Qdrant point payloads. Only store
doc_id,chunk_id,heading_path, andtagsin Qdrant payloads. The full text body is fetched from SQLite when needed. - ❌ DO NOT execute naive full re-indexing of documents on update. Always run differential chunk diffing via SHA-256 hashes.
- ❌ DO NOT delete records from Qdrant without updating the corresponding sync state in SQLite.
- ❌ DO NOT hardcode hyperparameters (chunk size, overlap, embedding model names, RRF constants). Expose them via
src/strata/core/config.pyusingpydantic-settings. - ❌ DO NOT place LLM generation logic inside retrieval or storage modules.