Incremental engine for long horizon agents π Star if you like it!
Rust agentic-data-frameworkaiai-agentschange-data-capturecodebase-intelligencecontext-engineeringdata-engineeringdata-indexingdata-processingetlhelp-wantedindexingknowledge-graphllmlong-horizon-agentpythonragreal-timerustsemantic-search
fix(examples): Rust multi-codebase and podcast LLM steps declare their model and entity types in deps (#2813)
LJ π₯₯π΄b8a7582ff0ef
diff --git a/examples/rust/conversation_to_knowledge/README.md b/examples/rust/conversation_to_knowledge/README.mdindex 4caf8754..979d6ecc 100644--- a/examples/rust/conversation_to_knowledge/README.md+++ b/examples/rust/conversation_to_knowledge/README.md@@ -19,6 +19,7 @@ sessions, statements, persons, techs, orgs, and the relationships between them.| Entity resolution | `ops.entity_resolution` (faiss + LLM) | `cocoindex::entity_resolution` + `fastembed` Snowflake embeddings + LLM pair resolver || Graph store | `surrealdb` connector (`TableTarget`/`RelationTarget`) | `cocoindex::connectors::surrealdb` targets over the native `surrealdb` crate || Embedder change-detection | `ContextKey(..., detect_change=True)` | `context_key!(..., detect_change)` with type-owned `MemoInput` behavior |+| Entity types in the Step 2 prompt | `deps={"prompt": STATEMENTS_PROMPT, ...}` | `deps = entity_prompt_lines()`, so editing `ENTITY_TYPES` or `entity_guidance` re-runs Step 2 |### Design notes / where it differsdiff --git a/examples/rust/conversation_to_knowledge/src/models.rs b/examples/rust/conversation_to_knowledge/src/models.rsindex 09a62489..efa88b26 100644--- a/examples/rust/conversation_to_knowledge/src/models.rs+++ b/examples/rust/conversation_to_knowledge/src/models.rs@@ -32,6 +32,20 @@ pub fn entity_guidance(kind: &str) -> (&'static str, &'static str) {}}+/// The entity-type lines of the statement-extraction prompt, one per entry in+/// `ENTITY_TYPES`. `extract_statements` lists this in `deps`: CocoIndex+/// fingerprints a function's own body, not the constants and plain helpers it+/// reads, so without it an edit here would leave old extractions cached.+pub fn entity_prompt_lines() -> String {+ ENTITY_TYPES+ .iter()+ .map(|kind| {+ let (desc, examples) = entity_guidance(kind);+ format!(" - {kind}: {desc} Examples: {examples}.\n")+ })+ .collect()+}+// ---------------------------------------------------------------------------// Transcript / source// ---------------------------------------------------------------------------diff --git a/examples/rust/conversation_to_knowledge/src/pipeline.rs b/examples/rust/conversation_to_knowledge/src/pipeline.rsindex 312008e9..25c4c0ff 100644--- a/examples/rust/conversation_to_knowledge/src/pipeline.rs+++ b/examples/rust/conversation_to_knowledge/src/pipeline.rs@@ -56,17 +56,15 @@ pub async fn extract_metadata(}/// Step 2: extract thematic statements + the entities they involve.-#[cocoindex::function(memo)]+/// `deps` covers the entity-type lines, which come from `models.rs`, so adding+/// or editing an entity type re-runs this step.+#[cocoindex::function(memo, deps = entity_prompt_lines())]pub async fn extract_statements(ctx: &Ctx,reformatted_transcript: &String,) -> Result<StatementExtraction> {let llm = ctx.get_key(&LLM)?;- let mut entity_lines = String::new();- for kind in ENTITY_TYPES {- let (desc, examples) = entity_guidance(kind);- entity_lines.push_str(&format!(" - {kind}: {desc} Examples: {examples}.\n"));- }+ let entity_lines = entity_prompt_lines();let system = format!("You are an expert knowledge extractor. Given a transcript where speakers are identified \by name, extract substantive thematic claims. Return a JSON object {{\"statements\": \diff --git a/examples/rust/multi_codebase_summarization/README.md b/examples/rust/multi_codebase_summarization/README.mdindex 06bdeae5..a3a59cf9 100644--- a/examples/rust/multi_codebase_summarization/README.md+++ b/examples/rust/multi_codebase_summarization/README.md@@ -45,14 +45,20 @@ cargo run -- ../.. ./output# Much faster β skips files and project summaries already analyzed```+**Switch the model** β the model and the `CodebaseInfo` schema are in the LLM steps' `deps`, so a new `LLM_MODEL` re-analyzes every file, unchanged ones included:++```sh+LLM_MODEL=gpt-4o cargo run -- ../.. ./output+```+## Macro ShowcaseThis example demonstrates:| Macro | Purpose ||---|---|-| `#[cocoindex::function(memo)]` | `extract_file_info` β LLM call cached per file fingerprint |-| `#[cocoindex::function(memo)]` | `aggregate_project_info` β LLM call cached until any file summary changes |+| `#[cocoindex::function(deps = llm_deps())]` | `extract_file_info` β one component per file, skipped while the file and `deps` are unchanged |+| `#[cocoindex::function(memo, deps = llm_deps())]` | `aggregate_project_info` β LLM call cached until any file summary or `deps` changes || `#[cocoindex::function]` | `generate_markdown` β pure transform, no caching needed || `ctx.scope(...)` | Mirror Python's per-project `coco.mount(...)` component || `ctx.mount_each(...)` | Process all files concurrently within each project |diff --git a/examples/rust/multi_codebase_summarization/src/main.rs b/examples/rust/multi_codebase_summarization/src/main.rsindex 603d50fa..2ce62411 100644--- a/examples/rust/multi_codebase_summarization/src/main.rs+++ b/examples/rust/multi_codebase_summarization/src/main.rs@@ -110,6 +110,15 @@ impl LlmClient {}}+/// What the LLM steps depend on beyond their source: the model and the output+/// schema (its field descriptions guide the LLM). Both live outside the+/// functions' bodies, so `deps` folds them into the functions' logic and a+/// change re-runs the extraction, unchanged files included. Evaluated once per+/// process, after `init_llm()` has set the model.+fn llm_deps() -> (String, serde_json::Value) {+ (llm().model.clone(), CodebaseInfo::json_schema())+}+fn should_skip_python_file(file: &FileEntry) -> bool {file.relative_path().components()@@ -127,8 +136,9 @@ fn should_skip_python_file(file: &FileEntry) -> bool {// ---------------------------------------------------------------------------/// Extract structured info from a single Python file via LLM.-/// `memo` caches results by file fingerprint β unchanged files are skipped.-#[cocoindex::function]+/// Mounted as one component per file: the component is skipped while the file+/// and this function's logic, `deps` included, are unchanged.+#[cocoindex::function(deps = llm_deps())]async fn extract_file_info(_ctx: &Ctx, file: FileEntry) -> Result<CodebaseInfo> {let content = file.content_str()?;let file_path = file.key();@@ -154,7 +164,7 @@ async fn extract_file_info(_ctx: &Ctx, file: FileEntry) -> Result<CodebaseInfo>/// Aggregate per-file summaries into a project-level summary via LLM./// `memo` caches the aggregation result until any file-level summary changes.-#[cocoindex::function(memo)]+#[cocoindex::function(memo, deps = llm_deps())]async fn aggregate_project_info(_ctx: &Ctx,project_name: String,diff --git a/examples/rust/multi_codebase_summarization/tests/example_smoke.rs b/examples/rust/multi_codebase_summarization/tests/example_smoke.rsindex 82d19f7c..06148c25 100644--- a/examples/rust/multi_codebase_summarization/tests/example_smoke.rs+++ b/examples/rust/multi_codebase_summarization/tests/example_smoke.rs@@ -319,6 +319,7 @@ fn run_example(output_dir: &Path,run_dir: &Path,base_url: &str,+ model: &str,) -> Output {Command::new(binary).arg(projects_dir)@@ -326,7 +327,7 @@ fn run_example(.current_dir(run_dir).env("LLM_API_KEY", "test-key").env("LLM_BASE_URL", base_url)- .env("LLM_MODEL", "mock-model")+ .env("LLM_MODEL", model).output().unwrap()}@@ -364,15 +365,17 @@ fn multi_codebase_example_runs_end_to_end_with_mock_llm() {let (base_url, request_count, stop, handle) = spawn_mock_llm();let binary = env!("CARGO_BIN_EXE_multi_codebase_summarization");- let run_once = || {+ let run_with_model = |model: &str| {run_example(binary,projects.path(),output.path(),run_dir.path(),&base_url,+ model,)};+ let run_once = || run_with_model("mock-model");let first = run_once();assert_success(&first, "first run");@@ -433,6 +436,16 @@ fn multi_codebase_example_runs_end_to_end_with_mock_llm() {assert_eq!(request_count.load(Ordering::Relaxed), 8);assert!(!output.path().join("beta.md").exists());+ // Switching the model re-analyzes every file, unchanged ones included:+ // alpha's three files plus its aggregation.+ let sixth = run_with_model("mock-model-v2");+ assert_success(&sixth, "sixth run");+ assert_eq!(request_count.load(Ordering::Relaxed), 12);++ let seventh = run_with_model("mock-model-v2");+ assert_success(&seventh, "seventh run");+ assert_eq!(request_count.load(Ordering::Relaxed), 12);+stop.store(true, Ordering::Relaxed);handle.join().unwrap();}@@ -457,6 +470,7 @@ fn multi_codebase_example_fails_on_missing_llm_content() {output.path(),run_dir.path(),&base_url,+ "mock-model",);assert_failure_contains(&output, "missing-content run", "no content in LLM response");@@ -485,6 +499,7 @@ fn multi_codebase_example_fails_on_malformed_llm_json() {output.path(),run_dir.path(),&base_url,+ "mock-model",);assert_failure_contains(&output, "malformed-json run", "LLM response parse");