Context-management primitives for rendering search results and tracking document spans shown to language models
Maintained. Last release 8 weeks ago, commits in 3 of the last 26 weeks. Weaker on commit activity and contributor spread.
pip install sid-sdkSID SDK
sid-sdk turns search results into compact, model-facing document views. It
assigns stable short IDs, selects relevant snippets, tracks the exact character
ranges already shown, masks repeated text, and renders SID's <doc> format.
Snippet selection is implemented in Rust with Alyze Unicode UAX #29 tokenization and separate unigram and bigram BM25 scores. Returned ranges are Python character offsets into the original text.
Installation
pip install sid-sdk
Prebuilt ABI3 wheels require no Rust compiler on supported macOS, Linux, and Windows platforms. Building from the source distribution requires Python 3.12+ and Rust 1.88 or newer.
Basic use
from sid import DocumentCache
cache = DocumentCache(language="english")
cache.add_document(
"database-id",
{"title": "Example", "content": "The complete document text ..."},
)
view = cache.apply_snippet(
"database-id",
snippet_field="content",
query="complete document",
)
print(view.render_xml())
cache.update_seen(view)
Named analyzers are available for Danish, Dutch, English, Finnish, French,
German, Hungarian, Italian, Norwegian, Portuguese, Russian, Spanish, and
Swedish. They lowercase tokens and remove Alyze's language-specific stopwords.
Use language="generic" for lowercase Unicode tokenization without stopword
removal. Chinese, Japanese, and Korean text is handled through generic UAX
#29 segmentation; there are no dedicated language entries. apply_snippet
accepts a one-call language= override, and forks inherit the cache default.
If every query token is a stopword, all windows have the same score and the selector deliberately returns the beginning of the document.
Model-facing IDs
New caches assign six ASCII digit strings, from "000000" through "999999",
instead of the previous five lowercase letters. IDs remain strings: preserve
leading zeros in storage, JSON tool schemas, and model responses. For example,
"004271" and the ranged reference "004271#10:70" identify the same document.
Database IDs are unchanged. Parsers still accept older letter-based references;
resolving any reference requires its original cache mapping.
Each cache family can mint 1,000,000 distinct IDs over its lifetime, down from
11,881,376. Exhaustion raises IdSpaceExhausted without recycling IDs. Forks
share the stream and mappings; independent caches can assign the same ID to
different documents, so keep references scoped to their cache family. Check
model-provided IDs with before using them.