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
- a.py
- b.md
- c.pdf Δ
- d.ts
- a.py
- b.md
- c.pdf Δ
- d.ts
<ul>{files.map((f) => (
<Row key={f.name} file={f} />
))}</ul>await coco.mount_each(
process_file,
files.items(), table)diff element trees
diff declared rows
- li a.pyuntouched
- li b.mduntouched
- li c.pdfpatched Δ
- li d.tsuntouched
1 node patched · 3 untouched
- 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.
01 Source
3 files02 Python flow
memo=Trueparse()cachedRead the document text.
0 run · 3 reusedsummarize()cachedKeep the first text line.
0 run · 3 reusedembed()cachedCreate a vector from the summary.
0 run · 3 reusedCached result = same function, same inputs.
03 Search index
doc_rowsOne row per file · summary + embedding
Your index is up to date. Change a file to see what runs again.
flow.pysimplified example# Simplified flow; helper implementations omitted.@coco.fn(memo=True)async def parse(file): ... @coco.fn(memo=True)async def summarize(doc, *, detail="short"): ... @coco.fn(memo=True)async def embed(text): ... async def process_file(file, target): doc = await parse(file) summary = await summarize(doc, detail="short") vector = await embed(summary) target.declare_row(row=DocRow( name=file.name, summary=summary, embedding=vector, ))The browser simulates parsing, summaries, and embedding reuse. Your Python flow uses real functions and a real target.
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.
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.@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.
| Concept | React | CocoIndex |
|---|---|---|
| State | Component state, props and context | Source items and their content fingerprints |
| One unit per item | files.map(...) renders one <Row> per file | coco.mount_each(...) mounts one component per file |
| Identity | key on each element, read only by the reconciler | The item key, which gives each component a stable path across runs |
| Diff | The reconciler compares the new element tree with the last one | The engine compares this run's declared rows with the ones it recorded last run |
| Commit | Patch the DOM nodes that differ | Upsert or delete the rows that differ |
| Skip unchanged work | memo | @coco.fn(memo=True) |
| Cleanup | Unmounted components leave the DOM | Rows from removed source items are deleted |
| Where results land | The DOM | Your 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.