Retrieval finds candidates.
ContextOS decides what
deserves the context window.
ContextOS is an open-source context orchestration layer that retrieves, ranks, and selects context within a strict token budget—then lets your application handle generation.
The context window is a budget.
Retrieval can tell you what is relevant. It cannot decide what deserves scarce context space.
ContextOS doesn't just retrieve more.
It chooses better.
By understanding the exact token footprint of every candidate, ContextOS runs a knapsack-style selection algorithm. It fills your context window with the absolute highest-value information without ever exceeding your token limits.
Hybrid Retrieval
Dense + lexical retrieval increases the chance that useful candidates enter the pool, ensuring exact keywords and semantic matches are both found.
Reranking
Candidates are evaluated together with the query using powerful cross-encoders before making any context selection decisions.
Token-Aware Planning
ContextOS accurately counts tokens and selects what perfectly fits inside the configured budget, discarding lower-relevance overflow.
Complex infrastructure.
Simple interface.
from contextos import ContextOS
context = ContextOS(...)
result = await context.build_context(
session_id=session_id,
query="Why did the database connection fail?",
)
print(result.context)Your model. Your stack.
ContextOS handles context selection. You decide how generation happens.
Open source by default.
Self-host ContextOS with PostgreSQL and pgvector. Inspect the implementation, reproduce the evaluations, and build on top of it.