React, for data.

This analogy starts with React: the UI is a function of state. In CocoIndex, your index or table is a function of your source data. When a source item changes, only its rows are rewritten.

React

CocoIndex

state · files
  • a.py
  • b.md
  • c.pdf Δ
  • d.ts
source · docs/
  • a.py
  • b.md
  • c.pdf Δ
  • d.ts
App.jsx
<ul>{files.map((f) => (
  <Row key={f.name} file={f} />
))}</ul>
flow.py
await coco.mount_each(
  process_file,
  files.items(), table)

diff element trees

diff declared rows

DOM · <ul>
  • li a.pyuntouched
  • li b.mduntouched
  • li c.pdfpatched Δ
  • li d.tsuntouched

1 node patched · 3 untouched

target · docs table
  • a.pyuntouched
  • b.mduntouched
  • c.pdfupserted Δ
  • d.tsuntouched

1 row upserted · 3 untouched

Change a file. Follow the update.

You write the Python. CocoIndex keeps the index in sync.

Interactive demo · simulated
docs_pipeline / local example
Try a change

01 Source

3 files
Try editing the first text line.

02 Python flow

memo=True
parse()cached

Read the document text.

0 run · 3 reused
summarize()cached

Keep the first text line.

0 run · 3 reused
embed()cached

Create a vector from the summary.

0 run · 3 reused

Cached result = same function, same inputs.

03 Search index

doc_rows
Document / summaryLast sync

One row per file · summary + embedding

3 files. An index that is already fresh.

Your index is up to date. Change a file to see what runs again.

3/3 embeddings reused
Sample data. No API calls or setup.
Build this with your own data.Open the docs

Write it like a component.

Both examples define a function for one item. A parent maps it over items with stable keys. Their memoization compares different inputs.

App.jsxUI = f(state)
import { memo } from "react";

const Row = memo(({ file }) => {
  const summary = summarize(file);
  return <li>{summary}</li>;
});

function App({ files }) {
  return <ul>{files.map((f) => (
    <Row key={f.name} file={f} />
  ))}</ul>;
}
memo compares each prop by reference. A new file object re‑renders the row even when its content is the same.
flow.pytarget = f(source)
@coco.fn(memo=True)
async def process_file(file, table):
    name = file.file_path.path.name
    summary = await summarize(file)
    row = DocRow(name, summary)
    table.declare_row(row=row)

@coco.fn
async def app_main(files, table):
    await coco.mount_each(
        process_file,
        files.items(),
        table,
    )
memo=True compares fingerprints of the file content and the process_file code, and keeps the result across runs.

Compare the two models.

React keeps its tree in memory. CocoIndex records declared target states in its state store. Each run compares against the previous state, including after a restart.

How React concepts correspond to CocoIndex concepts
ConceptReactCocoIndex
StateComponent state, props and contextSource items and their content fingerprints
One unit per itemfiles.map(...) renders one <Row> per filecoco.mount_each(...) mounts one component per file
Identitykey on each element, read only by the reconcilerThe item key, which gives each component a stable path across runs
DiffThe reconciler compares the new element tree with the last oneThe engine compares this run's declared rows with the ones it recorded last run
CommitPatch the DOM nodes that differUpsert or delete the rows that differ
Skip unchanged workmemo@coco.fn(memo=True)
CleanupUnmounted components leave the DOMRows from removed source items are deleted
Where results landThe DOMYour target: Postgres, Qdrant, LanceDB, files or Kafka

Try it on a local folder.

Write a small flow, change one file, and see the engine re‑run only that file.