fornix
Knowledge storage, retrieval, and graph infrastructure for cognitive systems.
fornix is a modular Rust library for building retrieval-heavy and agentic systems. It combines vector search, BM25 search, hybrid fusion, ontology-constrained extraction, graph reasoning, GraphRAG, routing, prompt tuning, and an autonomous tool-using agent runtime behind feature flags so you can enable only what you need.
Who This Is For
- Teams building RAG pipelines that need both lexical and semantic retrieval.
- Systems that need graph-aware retrieval and causal traversal.
- Agent runtimes that require strict policy controls around tool usage.
- Projects that want domain-constrained entity extraction with schema validation.
- Projects that prefer composable, feature-gated crates over monolithic frameworks.
Highlights
- Feature-gated architecture for lean builds.
- Pure in-memory adapters for fast local development and testing.
- Typed, composable APIs across storage, retrieval, graph, and agent layers.
- Ontology-constrained extraction: validated entity/relation types, alias resolution, per-type LLM prompt guidance.
- Built-in evaluation, filtering, and query-gap tracking for RAG workflows.
- End-to-end tested with unit tests plus doctests.
Installation
Add the crate with only the features you want.
[]
= { = "0.3", = ["vector", "bm25", "hybrid"] }
Or enable everything:
[]
= { = "0.3", = ["full"] }
Pick Features by Use Case
- Basic vector search:
vector - Keyword search:
bm25 - Hybrid retrieval (vector + BM25):
vector,bm25,hybrid - Ontology schema:
ontology - Graph knowledge layer:
graph - Graph + ontology validation:
graph,ontology - Graph-augmented retrieval with schema:
graphrag(pulls ingraph,rag,hybrid,ontology) - Prompt optimization:
rag,tuner - Agent runtime with routing:
router,agent
Feature Flags
The crate is layered; higher-level modules depend on lower-level ones:
store: base adapter traits, config, health, and error types.cache: caching adapters (store).vector: vector adapters and analysis (store).bm25: keyword retrieval adapters (store).hybrid: fused vector + BM25 retrieval (vector,bm25).ontology: domain-aware type schemas with alias resolution, validation, and prompt construction (store).graph: knowledge graph + temporal/causal APIs (store).rag: chunking, filters, eval, reranking (hybrid).graphrag: graph-augmented retrieval with ontology-constrained extraction (graph,rag,hybrid,ontology).router: model routing strategies + forest (cache).diff: boundary-aware textual diff snippets.tuner: prompt optimization strategies (rag).agent: recursive tool-using agent runtime (router).full: enables all modules.
The common module is always available.
Module Overview
store: foundational traits such asStorageAdapterandAdapterFactory.cache: memory/null cache adapters and deterministic cache keying.vector: vector storage, nearest-neighbor search, and embedding analytics.bm25: Okapi BM25 tokenization + scoring + indexing.hybrid: weighted fusion (Rrf,Linear) and confidence scoring.ontology: domain-aware type schemas —Definition,EntityTypeDefinition,RelationTypeDefinition,PropertyDefinition,OntologyValidator,OntologyPrompt,MemoryOntologyRegistry, alignment types. Mirrorscortex-ontology; JSON-serialisable for the Ruby native extension boundary.graph: entity/relation graph with bitemporal semantics and causal traversal. When theontologyfeature is also enabled,GraphConfigaccepts anontologyandontology_strictflag;OntologyViolationis the error raised in strict mode.graphrag: local/global/hybrid graph search modes. Always pulls inontology.GraphRagConfigacceptsontology: Option<Arc<Definition>>;effective_entity_types()/effective_relation_types()derive type lists from the ontology when set.rag: chunkers, post-filters, rerankers, evaluation metrics, query-gap tracker.router: regex, round-robin, weighted random, embedding-threshold, and RoRF routing.diff: focused and stitched snippets with change markers.tuner: MIPROv2, GEPA, and no-op prompt tuning.agent: solve loop with tool execution, recursion, policy controls, and token budgeting.
Quick Start
Most adapters are async. Use a Tokio runtime in your app:
use ;
use SearchOptions;
async
Ontology-Constrained GraphRAG
use Arc;
use ;
use GraphRagConfig;
Ontology-Validated Graph Writes
use Arc;
use Definition;
use GraphConfig;
JSON Boundary (Ruby Native Extension)
Definition serialises cleanly for the Ruby–Rust boundary:
use Definition;
let json = my_definition.to_json.unwrap;
// Pass JSON string to Ruby via Magnus; deserialise on the way back:
let def = from_json.unwrap;
Hybrid Retrieval
use ;
use ;
use ;
async
Graph + Causal Traversal
use ;
use CausalOptions;
async
Agent Runtime
The agent module provides an autonomous solve loop that can:
- call an injected model client,
- dispatch registered tools,
- recurse through sub-tasks,
- enforce policy constraints,
- track token/time/step budgets,
- compact memory when context grows.
You provide implementations for ModelClient and ToolRegistry.
Design Notes
commonis always available and not feature-gated.ontologyhas no async surface — all operations are synchronous andSend + Sync.- In-memory adapters are intentionally first-class for deterministic tests and local prototyping.
- Higher-level modules (
graphrag,agent) build on lower-level primitives rather than hiding them. - APIs favor explicit typed options (
SearchOptions,CausalOptions, config structs) over implicit globals. - The
ontologymodule is JSON-serialisable end-to-end to support the Ruby native extension boundary without any unsafe code.
Development
Run all tests:
Run clippy across all targets/features:
Run just the ontology module tests:
Notes on Adapters
- In-memory adapters are ideal for local development, integration tests, and reference behavior.
- Backend adapters (Postgres/Qdrant/Redis) are exposed as module surfaces; some implementations are currently stubs in this crate layout.
- For production deployments, verify backend adapter completeness against your selected features before rollout.
Versioning
Current crate version: 0.3.2.
As the module surface is broad and evolving, pin a minor version in production environments and review changelogs before upgrading.
License
MIT