ContextOS
Context Orchestration

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.

Open source Python PostgreSQL + pgvector LLM-agnostic
ContextOS
Context Budget2,184 / 4,000 tokens
Selected Context

The context window is a budget.

Retrieval can tell you what is relevant. It cannot decide what deserves scarce context space.

Traditional RAG
Query
Top K Retrieval
Prompt
ContextOS
Query
Retrieve
Fuse
Rerank
Budget
Context

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.

Context budget4,000 tokens
3,412 used588 remaining
+218asyncpg connection fix
+341connection pool configuration
-631unrelated PostgreSQL notes

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)
ContextResult
tokens_used:3412
budget:4000
selected_candidates:7
rejected_candidates:13

Your model. Your stack.

ContextOS handles context selection. You decide how generation happens.

ContextOS
ContextResult
OpenAI
Anthropic
Local LLM
Your Stack

See it in action.

Query
Why did asyncpg fail?
Context Budget3,412 / 4,000
Explore the full demo

Open source by default.

Self-host ContextOS with PostgreSQL and pgvector. Inspect the implementation, reproduce the evaluations, and build on top of it.

PythonPostgreSQLpgvectorMIT License