Skip to content

Latest commit

 

History

History
81 lines (60 loc) · 2.83 KB

library-quickstart.md

File metadata and controls

81 lines (60 loc) · 2.83 KB

Library quickstart

Use the Git dependency below.

Prerequisites: Git, and Rust 1.94.1 via rustup; 1.94.1 is the toolchain the repository's rust-toolchain.toml pins.

rustup toolchain install 1.94.1

Add workspace crates

The workspace manifests and lockfile pin ContextDB to one exact commit, which the README names.

git clone --branch dev https://github.com/context-graph-ai/context-graph.git
cargo +1.94.1 new my-app
cd my-app
cargo +1.94.1 add context-graph --path ../context-graph/crates/context-graph

Add the checked-out crate to your application’s Cargo.toml:

[dependencies]
context-graph = { path = "../context-graph/crates/context-graph" }

Optional EmbeddingGemma registration: add its sibling workspace path.

[dependencies]
candle-embeddinggemma = { path = "../context-graph/crates/candle-embeddinggemma" }

Write and read

Replace src/main.rs with this first offline memory write and read:

use std::collections::BTreeMap;
use context_graph::{CreateContext, CreateIntention, EmbedderConfig, Store, StoreConfig};

fn main() -> context_graph::Result<()> {
    let store = Store::open(StoreConfig {
        db_path: std::env::temp_dir()
            .join(format!("context-graph-example-{}.db", std::process::id())),
        default_text_embedder: Some(EmbedderConfig::disabled()),
        ..Default::default()
    })?;
    let context = store.create_context(CreateContext {
        name: "example".into(),
        labels: vec![],
        properties: BTreeMap::new(),
    })?;
    let item = store.create_intention(CreateIntention {
        description: "preserve one memory item".into(),
        context_id: context.id,
        ..Default::default()
    })?;
    let read_back = store.get_intention(item.id)?.expect("persisted intention");
    assert_eq!(read_back.description, item.description);
    Ok(())
}

The store schema refuses an Intention row whose Context id does not exist.

A created Intention can be read back after reopening the store.

A store configured with the disabled embedder records the disabled loader route.

cargo +1.94.1 run

A created Intention persists across store reopen.

These examples are illustrative; this page does not run doctests.

Next: library API and ontology.