Skip to content

Incremental engine for long horizon agents 🌟 Star if you like it!

9.0 KB
Raw Blame

AGENTS.md β€” CocoIndex examples

Guidance for AI coding agents (Claude Code, Cursor, etc.) working in this examples/ directory. Most top-level Python subfolders are self-contained, runnable CocoIndex v1 apps; rust/ contains Rust ports with per-example READMEs.

Before you write CocoIndex code: install the skill

CocoIndex v1 is a fundamental redesign from v0. Without context, LLMs tend to hallucinate the v0 flow-builder DSL and deprecated decorators. Install the official skill first β€” it teaches the correct v1 API. Quickest portable path for Codex and other Agent Skills-compatible clients is the hosted skill:

mkdir -p .agents/skills/cocoindex/references
curl -fsSL https://cocoindex.io/docs/skill.md -o .agents/skills/cocoindex/SKILL.md
for f in api_reference connectors patterns setup_database setup_project; do
  curl -fsSL https://cocoindex.io/docs/references/$f.md -o .agents/skills/cocoindex/references/$f.md
done

Or clone the repo and copy the folder:

git clone --depth=1 https://github.com/cocoindex-io/cocoindex.git /tmp/cocoindex-skill
mkdir -p .agents/skills && cp -r /tmp/cocoindex-skill/skills/cocoindex .agents/skills/

For Claude Code's native project path, use .claude/skills/cocoindex instead of .agents/skills/cocoindex; the skill format is the same.

The skill itself lives at skills/cocoindex/ (SKILL.md + references/). For Cursor, copy SKILL.md into .cursor/rules/. Full machine-readable docs: https://cocoindex.io/docs/llms.txt (index) and https://cocoindex.io/docs/llms-full.txt (everything, including example walkthroughs). Regular docs pages also have raw Markdown twins by replacing the trailing slash with .md (e.g. https://cocoindex.io/docs/programming_guide/core_concepts.md).

The v1 mental model

target_state = transform(source_state). You declare what the target should look like; the Rust engine keeps it in sync, reprocessing only what changed (state is tracked in a local LMDB store β€” no database is required for the engine itself, only when an example writes to one). Key APIs: @coco.fn, mount / use_mount / mount_each, ContextKey, target-state declarations. See the skill for details.

Running examples

Most Python examples are standalone projects with their own pyproject.toml:

cd <example_dir>
cp .env.example .env          # if present β€” fill in the blanks (see below)
pip install -e .              # or: uv pip install -e .
cocoindex update main         # catch-up: scan sources, sync, exit
cocoindex update -L main      # live mode: catch up, then watch for changes (where supported)

Use the example's README as the source of truth. Known exceptions:

  • multi_codebase_summarization, audio_to_text, patient_intake_extraction_baml, patient_intake_extraction_dspy: cocoindex update main.py
  • conversation_to_knowledge: cocoindex update conv_knowledge.app
  • image_search, image_search_colpali: start the API with python -m uvicorn api:app --reload --host 0.0.0.0 --port 8000; it runs the CocoIndex app in live mode, then start the frontend from frontend/.
  • csv_to_kafka, kafka_to_lancedb: cocoindex update -L main.py
  • rust/<example>: follow that example's README. Many use cargo run -- index for indexing and cargo run -- query "..." for search; a few take custom paths or service-specific subcommands.

Some examples expose a query/CLI demo via python main.py "<query>"; check the example's README.md. Examples that need extra services or a code-gen step (e.g. baml generate) say so in their README.

Environment / credentials

When an example needs credentials or service configuration, required env vars are templated in that example's .env.example β€” cp it to .env and fill in the blanks; both python main.py and the cocoindex CLI load .env automatically. Common ones:

  • POSTGRES_URL β€” for Postgres/pgvector targets. Local instance: docker compose -f ../../dev/postgres.yaml up -d from inside an example directory.
  • OPENAI_API_KEY / GEMINI_API_KEY β€” for examples that call an LLM.
  • Service-specific (QDRANT_URL, LANCEDB_URI, NEO4J_*, KAFKA_*, GOOGLE_SERVICE_ACCOUNT_CREDENTIAL, …) β€” see that example's .env.example.

Examples with no .env.example (e.g. files_transform, pdf_to_markdown) run fully locally with no credentials.

Never commit secrets. The .env files tracked in this repo hold only non-secret defaults (COCOINDEX_DB, local service URLs); keep API keys and credentials in your local .env edits and out of commits.

The examples

A walkthrough URL means there's a step-by-step guide at https://cocoindex.io/docs/examples/<slug>/; otherwise start from the example's README.

Vector indexes (embed β†’ store β†’ search by meaning)

  • text_embedding β€” Markdown β†’ pgvector; the simplest end-to-end index. (walkthrough: text-embedding)
  • code_embedding β€” repo β†’ Tree-sitter chunks β†’ pgvector; query code in English. (walkthrough: index-codebase)
  • text_embedding_qdrant / text_embedding_lancedb / text_embedding_turbopuffer β€” same flow, different vector store.
  • code_embedding_lancedb β€” code chunks β†’ LanceDB.
  • pdf_embedding β€” PDFs β†’ markdown β†’ chunks β†’ pgvector.
  • paper_metadata β€” extract title/authors/abstract from PDFs β†’ Postgres + embeddings.
  • amazon_s3_embedding / gdrive_text_embedding / oci_object_storage_embedding β€” same flow, remote source (S3 / Google Drive / OCI).
  • discord_text_embedding β€” Discord forum posts and messages β†’ chunks β†’ pgvector, with a script that seeds a forum.
  • postgres_source β€” read from an existing Postgres table as the source.
  • entire_session_search β€” semantic search over AI coding sessions captured by Entire.
  • sec_edgar_analytics β€” multi-format SEC filings β†’ Apache Doris with a vector and a full-text index; hybrid (semantic + keyword) RRF search. (walkthrough: sec-edgar-analytics)

Multimodal

  • image_search β€” CLIP embeddings + Qdrant, queried via FastAPI + React.
  • image_search_colpali β€” ColPali multi-vector model + Qdrant MaxSim.
  • pdf_elements_embedding β€” PDF pages β†’ text chunks (MiniLM) + images (CLIP) β†’ two Qdrant collections; one query searches both.
  • multi_format_indexing β€” PDFs + images as page screenshots β†’ ColPali β†’ Qdrant; no OCR, no chunking. (walkthrough: multi-format-indexing)
  • face_recognition β€” detect faces (dlib) β†’ 128-d embeddings β†’ Qdrant face search. (walkthrough: face-recognition)
  • audio_to_text β€” transcribe audio with LiteLLM β†’ Postgres.
  • slides_to_speech β€” slides β†’ vision-LLM notes β†’ Pocket TTS narration β†’ LanceDB semantic search. (walkthrough: slides-to-speech)

Structured extraction (LLM / BAML / DSPy)

  • multi_codebase_summarization β€” LLM per-file summaries across many repos. (walkthrough: multi-codebase-summarization)
  • hn_trending_topics β€” scrape HackerNews β†’ LLM topic extraction β†’ Postgres.
  • manuals_llm_extraction β€” PDF manuals β†’ Markdown (docling) β†’ typed module records β†’ Postgres. (walkthrough: manuals-llm-extraction)
  • patient_intake_extraction_baml / patient_intake_extraction_dspy β€” structured PDF extraction with BAML / DSPy (Gemini vision).
  • discord_support_faq β€” Discord support threads β†’ LLM question and answer β†’ entity resolution merges repeats β†’ FAQ.md, a knowledge base for an agent that stays current, with a script that seeds a forum.

Knowledge graphs

  • conversation_to_knowledge β€” YouTube podcasts β†’ SurrealDB knowledge graph. (walkthrough: podcast-to-knowledge-graph)
  • docs_to_knowledge_graph β€” Markdown docs β†’ Neo4j concept graph of LLM-extracted triples. (walkthrough: docs-to-knowledge-graph)
  • product_recommendation β€” product catalog β†’ LLM taxonomy extraction β†’ Neo4j recommendation graph. (walkthrough: product-recommendation)
  • meeting_notes_graph_neo4j / meeting_notes_graph_falkordb β€” Google Drive meeting notes β†’ Neo4j / FalkorDB graph.
  • meeting_notes_graph_surrealdb β€” local Markdown meeting notes β†’ SurrealDB graph.

Custom sources / targets / streaming

  • pdf_to_markdown β€” incremental PDF β†’ Markdown with docling (local, no services). (walkthrough: pdf-to-markdown)
  • files_transform β€” watch Markdown files β†’ HTML, live mode (local, no services).
  • csv_to_kafka β€” watch CSVs β†’ publish rows to Kafka.
  • kafka_to_lancedb β€” consume Kafka β†’ route to LanceDB tables.

Rust

  • rust/ β€” Rust ports of many of the above, using the CocoIndex Rust API.

Conventions for edits

  • Keep each Python example self-contained: its own pyproject.toml and README.md; add .env.example when credentials or configurable services are required. When you add an example, also add a line to EXAMPLE_CATALOG in the docs repo (docs/src/data/examples.ts) so it appears in /docs/llms.txt.
  • Match the surrounding code's low comment density.
  • Don't commit generated artifacts (cocoindex.db, __pycache__, build output) β€” they're already git-ignored.