A Context Database for AI Agents
OrionGraphDB is an open-source context compilation engine that provides intelligent, budget-aware retrieval for AI agents. It combines semantic, lexical, and structural search with MMR-based selection to deliver optimal context within token budgets.
Think of OrionGraphDB as "Postgres for AI Context":
- Stores and indexes code, documents, and knowledge bases
- Retrieves optimal context for any AI task
- Respects token budgets and diversity constraints
- Explains why each piece of context was selected
- Multi-Channel Retrieval: Semantic, lexical (BM25), and structural search
- MMR Selection: Maximal Marginal Relevance for diverse, relevant context
- Token Budget Management: Never exceed your LLM's context window
- Citation-Friendly: Every span has a stable reference and source
- HTTP API: Language-agnostic REST interface
- Fast: Built in Rust for production performance
# Build and run
cargo build --release
./target/release/oriongraph-server
# Server runs at http://localhost:8081from oriongraph_client import OrionGraphClient
client = OrionGraphClient("http://localhost:8081")
# Compile optimal context
result = client.compile_workingset(
intent="Find rollback procedures for database migrations",
budget_tokens=6000,
workstream="migration",
)
# Use the context
for span in result["workingset"]["spans"]:
print(f"π {span['span_ref']['doc_version_id']}")
print(f" {span['text'][:100]}...")A span is an addressable unit of context:
- Has a unique
span_id - Belongs to a
doc_version_id - Has a known
token_cost - Contains semantic, lexical, and structural metadata
A working set is a compiled selection of spans:
- Fits within a token budget
- Maximizes relevance to the intent
- Ensures diversity (via MMR)
- Includes explanations for each selection
OrionGraphDB uses three channels:
- Semantic: Vector embeddings for meaning-based search
- Lexical: BM25 for keyword/term matching
- Structural: Project structure, imports, definitions
Implementation Status: See FEATURES.md for what's currently implemented vs. planned.
OrionGraphDB
βββ Context Engine (Core retrieval logic)
βββ Generators (Semantic, Lexical, Structural)
βββ Scoring & Selection (MMR algorithm)
βββ HTTP Server (REST API)
Technology Stack:
- Rust - Performance and safety
- Axum - HTTP framework
- Tokio - Async runtime
- Serde - Serialization
Compile an optimal context working set.
Request:
{
"intent": "Find error handling patterns",
"budget_tokens": 6000,
"workstream": "backend",
"explain": true
}Response:
{
"workingset": {
"spans": [
{
"span_ref": {
"doc_version_id": "src/error.rs",
"span_id": "fn_handle_error",
"token_cost": 150
},
"text": "pub fn handle_error(err: Error) -> Response { ... }"
}
],
"total_tokens": 1243
},
"stats": {
"candidates_generated": 47,
"token_utilization": 0.82
}
}Check server health.
Response:
{
"status": "healthy",
"version": "0.1.0"
}See examples/python-client/ for a full Python client.
from oriongraph_client import OrionGraphClient
client = OrionGraphClient()
result = client.compile_workingset(intent="...", budget_tokens=6000)from oriongraph_client import OrionGraphClient
def get_context(query: str) -> str:
client = OrionGraphClient()
result = client.compile_workingset(intent=query, budget_tokens=4000)
return "\n\n".join(span["text"] for span in result["workingset"]["spans"])OrionGraphDB works with any agent framework via its HTTP API.
cargo buildcargo testcargo run --releasedocker build -t oriongraphdb .
docker run -p 8081:8081 oriongraphdb- Run as a systemd service or Docker container
- Use a reverse proxy (Nginx, Caddy) for HTTPS
- Scale horizontally with load balancing
- Store indices on persistent volumes
Retrieve relevant code snippets for any programming task.
Compile optimal context for document Q&A.
Shared context database for collaborative agents.
Query runbooks, deployment procedures, and infrastructure docs.
We welcome contributions! OrionGraphDB is open-source under the Apache 2.0 license.
How to Contribute:
- Fork the repo
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
Areas We'd Love Help With:
- Additional generators (e.g., time-based, git-history)
- Performance benchmarks
- Client libraries (Node.js, Go, Rust)
- Documentation and examples
Apache 2.0 - See LICENSE
- GitHub: github.com/servesys-labs/oriongraphdb
- Issues: github.com/servesys-labs/oriongraphdb/issues
- Orion Framework: github.com/servesys-labs/orion (proprietary)
OrionGraphDB is part of the Orion Stack ecosystem:
- OrionGraphDB (this repo) - Context database
- Orion Agents - Agent framework (private)
- Orion CLI - Developer tooling (private)
Built with β€οΈ by the Orion team.