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): podcast and multi-codebase LLM steps declare their prompts and model in deps (#2812)
LJ π₯₯π΄33000250ec7e
diff --git a/docs/src/content/example-posts/multi-codebase-summarization.md b/docs/src/content/example-posts/multi-codebase-summarization.mdindex 53cf4546..5301fba3 100644--- a/docs/src/content/example-posts/multi-codebase-summarization.md+++ b/docs/src/content/example-posts/multi-codebase-summarization.md@@ -256,7 +256,9 @@ The core extraction function uses memoization to cache LLM results:````python title="main.py"_instructor_client = instructor.from_litellm(acompletion, mode=instructor.Mode.JSON)[email protected](memo=True)+_LLM_DEPS = {"model": LLM_MODEL, "schema": CodebaseInfo.model_json_schema()}+[email protected](memo=True, deps=_LLM_DEPS)async def extract_file_info(file: FileLike) -> CodebaseInfo:"""Extract structured information from a single Python file using LLM."""content = await file.read_text()@@ -288,6 +290,8 @@ Instructions:**Why `memo=True` matters:** LLM calls are expensive. With memoization, CocoIndex caches the result keyed by the file content. If you run the pipeline again without changing a file, the cached result is usedβno LLM call needed.+**Why `deps=` matters:** CocoIndex fingerprints the function's source code, not the module-level values it reads. `LLM_MODEL` comes from an environment variable, and the `CodebaseInfo` field descriptions reach the LLM through instructor, so neither appears in the function's source. [`deps`](/docs/programming_guide/function/#deps) adds both to the function's logic fingerprint. Switch `LLM_MODEL` or edit a field description, and every file is re-analyzed on the next run. Without `deps=`, files that did not change keep the old model's output.+[β Function](/docs/programming_guide/function/)@@ -298,7 +302,7 @@ For projects with multiple files, we aggregate into a unified summary:```python title="main.py"[email protected](deps=_LLM_DEPS)async def aggregate_project_info(project_name: str,file_infos: list[CodebaseInfo],@@ -468,6 +472,14 @@ cocoindex update main.pyOnly the modified file is re-analyzed by the LLM. Unchanged files use cached results.+**Switch the model:**++```bash+LLM_MODEL=gemini/gemini-2.5-pro cocoindex update main.py+```++Every file is re-analyzed with the new model, because `LLM_MODEL` is in `deps=`.+**Add a new project:**Add a new subdirectory with Python files:diff --git a/docs/src/content/example-posts/podcast-to-knowledge-graph.md b/docs/src/content/example-posts/podcast-to-knowledge-graph.mdindex ac9938f9..f1bf4eed 100644--- a/docs/src/content/example-posts/podcast-to-knowledge-graph.md+++ b/docs/src/content/example-posts/podcast-to-knowledge-graph.md@@ -80,7 +80,10 @@ There's a bootstrapping problem: to attribute statements correctly, the LLM need**Step 1 β identify speakers and extract metadata.** Format the transcript with generic labels, give the LLM the YouTube metadata as context, and get back typed speaker identifications. The output is a Pydantic model, enforced by [instructor](https://github.com/instructor-ai/instructor) over [LiteLLM](/docs/ops/litellm/):```python title="conv_knowledge/extract.py"[email protected](memo=True)+ memo=True,+ deps={"prompt": METADATA_PROMPT, "schema": SessionMetadata.model_json_schema()},+)async def extract_metadata(reformatted_transcript: str, transcript: SessionTranscript) -> SessionMetadata:client = instructor.from_litellm(litellm.acompletion, mode=instructor.Mode.JSON)return await client.chat.completions.create(@@ -113,6 +116,19 @@ class RawStatement(pydantic.BaseModel):mentioned_org: list[str] # ["OpenAI"]```+Step 2 follows the same pattern. Its prompt, `STATEMENTS_PROMPT`, is built from `ENTITY_TYPES`, so each entity type's description and examples are part of it:++```python title="conv_knowledge/extract.py"+ memo=True,+ deps={"prompt": STATEMENTS_PROMPT, "schema": StatementExtraction.model_json_schema()},+)+async def extract_statements(reformatted_transcript: str) -> StatementExtraction:+ ...+```++**Why `deps=`:** CocoIndex fingerprints a function's source code, not the module-level values it reads. The prompts are module-level strings, and the Pydantic field descriptions reach the LLM through instructor's JSON schema. [`deps`](/docs/programming_guide/function/#deps) adds both to each step's logic fingerprint, so editing a prompt or the output schema re-runs that step on the next update. Without `deps=`, the edit has no effect on episodes already processed.+Every name must be **self-contained** (the prompt forbids pronouns, speaker labels, or contextual references) because statements from different episodes get cross-referenced later, and a name like "he" or "the host" is meaningless outside its transcript.### Declare the session and statements@@ -218,9 +234,9 @@ This isn't a one-shot job β you'll add episodes over time and evolve the schem| Pipeline step | What happens | Why ||---|---|---|| Fetch transcript | **Reused** | Memoized, input unchanged |-| Step 1: speaker identification | **Reused** | Prompt unchanged |-| Step 2: statement extraction | **Re-runs** | Extraction prompt changed |-| Entity resolution (person, tech, org) | **Reused** | Raw entities unchanged |+| Step 1: speaker identification | **Reused** | Its prompt and schema are unchanged |+| Step 2: statement extraction | **Re-runs** | `STATEMENTS_PROMPT`, a `deps` value, changed |+| Entity resolution (person, tech, org) | **Mostly reused** | Names seen before hit cached embeddings and pair decisions || Entity resolution (product) | **Runs fresh** | New type || Knowledge base creation | **Re-declared** | New nodes + relationships |diff --git a/examples/conversation_to_knowledge/README.md b/examples/conversation_to_knowledge/README.mdindex e71c5258..6ed80124 100644--- a/examples/conversation_to_knowledge/README.md+++ b/examples/conversation_to_knowledge/README.md@@ -72,6 +72,7 @@ statement_mentions_rel = await surrealdb.mount_relation_target(- **Structured LLM extraction.** OpenAI (via LiteLLM) + Pydantic models pull speakers, thematic statements, and mentioned entities as *typed data* β not freeform text you have to re-parse.- **Entity resolution, built in.** [`resolve_entities`](https://cocoindex.io/docs/ops/entity_resolution/) collapses near-duplicate people, techs, and orgs using embedding similarity + LLM confirmation, so the graph has one canonical node per real-world thing.- **Incremental, per episode.** `@coco.fn(memo=True)` with one component per YouTube ID means adding an episode processes only that episode; unchanged sessions are skipped.+- **Prompt edits re-run only what they touch.** Each extraction step lists its prompt and output schema in `deps=`, so editing `STATEMENTS_PROMPT` or adding an entity type re-runs statement extraction for every episode, and nothing else. Without `deps=`, an edit to a module-level prompt leaves the old results cached: CocoIndex fingerprints a function's source, not the values it reads.- **A real graph, declaratively.** Nodes and polymorphic relationships are declared as target states; CocoIndex syncs them into [SurrealDB](https://cocoindex.io/docs/connectors/) and cleans up what's gone β no migration scripts.- **Plain async Python, swappable parts.** Transcriber, LLM, embedder, and graph store are all yours to change.diff --git a/examples/conversation_to_knowledge/conv_knowledge/extract.py b/examples/conversation_to_knowledge/conv_knowledge/extract.pyindex 7e9c994f..d58ffaf6 100644--- a/examples/conversation_to_knowledge/conv_knowledge/extract.py+++ b/examples/conversation_to_knowledge/conv_knowledge/extract.py@@ -70,7 +70,16 @@ identify with their full name β omit any speaker you cannot identify. Do not g"""[email protected](memo=True)+# `deps` puts the prompt and the output schema (whose field descriptions the LLM+# also reads) into the function's logic: editing either re-runs Step 1.+# CocoIndex fingerprints the function's source, not module-level values.+ memo=True,+ deps={+ "prompt": METADATA_PROMPT,+ "schema": SessionMetadata.model_json_schema(),+ },+)async def extract_metadata(reformatted_transcript: str, transcript: SessionTranscript) -> SessionMetadata:@@ -153,7 +162,15 @@ and factual assertions.STATEMENTS_PROMPT = _build_statements_prompt()[email protected](memo=True)+# STATEMENTS_PROMPT is built from ENTITY_TYPES, so adding or editing an entity+# type changes it and re-runs Step 2, as does an edit to the output schema.+ memo=True,+ deps={+ "prompt": STATEMENTS_PROMPT,+ "schema": StatementExtraction.model_json_schema(),+ },+)async def extract_statements(reformatted_transcript: str,) -> StatementExtraction:diff --git a/examples/conversation_to_knowledge/design.md b/examples/conversation_to_knowledge/design.mdindex a36640d8..097f6ef5 100644--- a/examples/conversation_to_knowledge/design.md+++ b/examples/conversation_to_knowledge/design.md@@ -233,7 +233,10 @@ def reformat_transcript(#### LLM Step 1: Extract Metadata + Identify Speakers```python[email protected](memo=True)+ memo=True,+ deps={"prompt": METADATA_PROMPT, "schema": SessionMetadata.model_json_schema()},+)async def extract_metadata(reformatted_transcript: str, transcript: SessionTranscript) -> SessionMetadata:"""Give LLM the reformatted transcript + all YouTube metadata to identify speakers."""client = instructor.from_litellm(litellm.acompletion, mode=instructor.Mode.JSON)@@ -262,12 +265,17 @@ The identified speakers (those with non-None names) form the *person_session* re#### LLM Step 2: Extract Statements```python[email protected](memo=True)+ memo=True,+ deps={"prompt": STATEMENTS_PROMPT, "schema": StatementExtraction.model_json_schema()},+)async def extract_statements(reformatted_transcript: str) -> StatementExtraction:"""Extract statements and involved entities from the reformatted transcript."""...```+`deps=` puts each step's prompt and output schema into its logic fingerprint, because CocoIndex fingerprints function source, not module-level values. `STATEMENTS_PROMPT` is built from `ENTITY_TYPES`, so adding or editing an entity type re-runs Step 2 for every session.+The Step 2 prompt instructs the LLM to:- Extract thematic statements with speaker attributions and involved entities- Use Wikipedia-style canonical names (e.g. "Franklin D. Roosevelt", "Python (programming language)")diff --git a/examples/multi_codebase_summarization/README.md b/examples/multi_codebase_summarization/README.mdindex 3dd0a48f..f3e04d8c 100644--- a/examples/multi_codebase_summarization/README.md+++ b/examples/multi_codebase_summarization/README.md@@ -35,7 +35,11 @@ Your code is the source of truth, but a hand-written wiki drifts the moment someEach top-level subdirectory is treated as a project. The pipeline extracts a structured `CodebaseInfo` per file with an LLM, aggregates files into a project summary, and writes Markdown with Mermaid diagrams. Read it in [`main.py`](main.py):```python[email protected](memo=True) # per file β structured LLM extraction, cached by content+# The model and schema are module-level values that CocoIndex cannot see in the+# function's source, so `deps=` declares them: changing either re-runs the extraction.+_LLM_DEPS = {"model": LLM_MODEL, "schema": CodebaseInfo.model_json_schema()}+[email protected](memo=True, deps=_LLM_DEPS) # per file β structured LLM extraction, cached by contentasync def extract_file_info(file: FileLike) -> CodebaseInfo:result = await _instructor_client.chat.completions.create(model=LLM_MODEL, response_model=CodebaseInfo,@@ -73,7 +77,7 @@ Extraction is [instructor](https://github.com/instructor-ai/instructor) over [Li## Why it's worth a star β- **Always fresh, never by hand.** The wiki is a [target state](https://cocoindex.io/docs/programming_guide/target_state/) regenerated from the code β edit a file and the one-pager updates itself; the docs can't drift from the source.-- **Incremental by default.** `@coco.fn(memo=True)` caches each file's extraction by content, so re-running only re-analyzes changed files. Add a project and only that project is processed.+- **Incremental by default.** `@coco.fn(memo=True)` caches each file's extraction by content, so re-running only re-analyzes changed files. Add a project and only that project is processed. Switch `LLM_MODEL` and every file is re-analyzed with the new model, because the model is in `deps=`.- **Concurrent by construction.** `coco.map(extract_file_info, files)` fans every file out at once while staying visible to the pipeline β far faster than sequential LLM calls.- **You pick the granularity.** Here it's one wiki page per project directory, but the same shape works per file, per page, or per semantic unit.- **Structured outputs, your stack.** One `CodebaseInfo` Pydantic model drives both file- and project-level extraction; swap `LLM_MODEL` for any [LiteLLM provider](https://docs.litellm.ai/docs/providers).diff --git a/examples/multi_codebase_summarization/main.py b/examples/multi_codebase_summarization/main.pyindex fdab488b..13bbfe19 100644--- a/examples/multi_codebase_summarization/main.py+++ b/examples/multi_codebase_summarization/main.py@@ -35,7 +35,13 @@ _instructor_client = cast()[email protected](memo=True)+# `deps` puts the model and the output schema (whose field descriptions the LLM+# also reads) into the function's logic, so changing either re-runs the+# extraction. CocoIndex fingerprints the function's source, not module-level values.+_LLM_DEPS = {"model": LLM_MODEL, "schema": CodebaseInfo.model_json_schema()}++[email protected](memo=True, deps=_LLM_DEPS)async def extract_file_info(file: FileLike) -> CodebaseInfo:"""Extract structured information from a single Python file using LLM."""content = await file.read_text()@@ -65,7 +71,7 @@ Instructions:return CodebaseInfo.model_validate(result.model_dump())[email protected](deps=_LLM_DEPS)async def aggregate_project_info(project_name: str,file_infos: list[CodebaseInfo],