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
docs(getting-started): the Why CocoIndex page compares a pipeline with and without CocoIndex (#2892)
Jiangzhou471e8685f1db
diff --git a/docs/src/components/Formula.astro b/docs/src/components/Formula.astronew file mode 100644index 00000000..6f48db7d--- /dev/null+++ b/docs/src/components/Formula.astro@@ -0,0 +1,18 @@+---+// A formula on a line of its own, centered in the text column. Write the+// formula as Markdown inside the tags, so that the Markdown twin of the page+// keeps it.+---+<div class="formula"><slot /></div>++<style>+ .formula {+ max-width: var(--measure);+ margin: 20px 0;+ text-align: center;+ }+ :global(.prose) .formula :global(p) {+ margin: 0;+ font-size: 1.125rem;+ }+</style>diff --git a/docs/src/components/Mark.astro b/docs/src/components/Mark.astronew file mode 100644index 00000000..e8fa6706--- /dev/null+++ b/docs/src/components/Mark.astro@@ -0,0 +1,25 @@+---+// Colors a β or β in a comparison table: `<Mark good>β</Mark>` is green,+// `<Mark bad>β</Mark>` is pink. The glyph is typed in the page, not drawn+// here, so that the Markdown twin of the page keeps it. A cell that starts+// with a mark hangs its text: a wrapped line starts under the text, not under+// the mark.+interface Props {+ good?: boolean;+ bad?: boolean;+}+const { good = false, bad = false } = Astro.props;+---+<span class:list={['mark', { 'mark--good': good, 'mark--bad': bad }]}><slot /></span>++<style>+ .mark { display: inline-block; width: 1.25em; font-weight: 600; text-indent: 0; }+ /* 14px is the cell's own left padding (site.css). The mark and the space+ after it take 1.5em. */+ :global(.prose td:has(> .mark:first-child)) {+ padding-left: calc(14px + 1.5em);+ text-indent: -1.5em;+ }+ .mark--good { color: var(--palm); }+ .mark--bad { color: var(--pink); }+</style>diff --git a/docs/src/components/UseCase.astro b/docs/src/components/UseCase.astroindex 68c19aae..eb475901 100644--- a/docs/src/components/UseCase.astro+++ b/docs/src/components/UseCase.astro@@ -8,12 +8,17 @@ import UseCaseArt from './diagrams/concepts/UseCaseArt.astro';interface Props {art: Parameters<typeof UseCaseArt>[0]['kind'];+ /** A short tag above the text, such as "Target" or "Pattern". */+ label?: string;}-const { art } = Astro.props;+const { art, label } = Astro.props;---<div class="uc-card"><div class="uc-card__art"><UseCaseArt kind={art} /></div>- <div class="uc-card__body"><slot /></div>+ <div class="uc-card__body">+ {label && <p class="uc-card__label">{label}</p>}+ <slot />+ </div></div><style>@@ -40,11 +45,30 @@ const { art } = Astro.props;line-height: 1.5;color: var(--muted);}- :global(.prose) .uc-card__body :global(p:first-child) {+ :global(.prose) .uc-card__body .uc-card__label {+ margin: 0 0 6px;+ font-family: var(--mono);+ font-size: 0.75rem;+ line-height: 1.3;+ color: var(--text-3);+ }+ /* The title is the first paragraph of the page's Markdown. */+ :global(.prose) .uc-card__body :global(p:first-child:not(.uc-card__label)),+ :global(.prose) .uc-card__body .uc-card__label + :global(p) {font-size: 1rem;line-height: 1.3;letter-spacing: -0.01em;color: var(--maroon-ink);}:global(.prose) .uc-card__body :global(p:last-child) { margin-bottom: 0; }+ /* The site's link style skips anything inside a "card" class, so the card+ gives its links the same underline. */+ :global(.prose) .uc-card__body :global(a) {+ color: var(--maroon-ink);+ text-decoration: underline;+ text-decoration-color: var(--rule-strong);+ text-decoration-thickness: 1px;+ text-underline-offset: 3px;+ }+ :global(.prose) .uc-card__body :global(a:hover) { text-decoration-color: var(--muted); }</style>diff --git a/docs/src/components/diagrams/README.md b/docs/src/components/diagrams/README.mdindex 020eeddd..5da7fb01 100644--- a/docs/src/components/diagrams/README.md+++ b/docs/src/components/diagrams/README.md@@ -68,7 +68,9 @@ src/components/diagrams/βββ FileProcess.astro # thin wrapper around ComponentPerFile w/ highlightβββ ComponentsFanout.astro # thin wrapper around ComponentPerFile w/ highlightβββ ComponentWithChunks.astro # Drive β App(PCβSplitβchunksβEmbedβvectors) β VDB- β # accepts `memoized`, `scenario` and `componentLabel` props+ β # accepts `memoized`, `scenario`, `componentLabel`,+ β # `sourceLabel`, `targetLabel` and `dimReused` props+ βββ SourcesToTargets.astro # kinds of source β the reader's functions β kinds of target (overview)βββ UseCaseArt.astro # abstract card art for a use case (overview); wrapped by components/UseCase.astro```@@ -193,6 +195,7 @@ Do not hardcode hex values in diagrams. Always use the vars.- `dg-state-{new,updated,removed,changed}` β delta states (direct-child scoped)- `dg-status-badge--ok` / `--refresh` β status badge variants- `dg-highlight` β thick palm border for "currently discussed"+- `dg-dim` β work that a run did not repeat (skipped or reused), at reduced opacity- `dg-flow` β animated dashed arrow- `dg-connector` β static binding line- `dg-pulse` β pulsing dotdiff --git a/docs/src/components/diagrams/concepts/ComponentWithChunks.astro b/docs/src/components/diagrams/concepts/ComponentWithChunks.astroindex da54fedb..8a9bcf13 100644--- a/docs/src/components/diagrams/concepts/ComponentWithChunks.astro+++ b/docs/src/components/diagrams/concepts/ComponentWithChunks.astro@@ -41,8 +41,18 @@ interface Props {/** Header of each component box. Defaults to "Processing Component";a page that has not introduced that term passes the function's name. */componentLabel?: string;+ /** Names of the source and the target, when a page has its own example. */+ sourceLabel?: string;+ targetLabel?: string;+ /** Dim what this run did not repeat: a component with a cache hit, and+ an embedding with a cache hit together with its unchanged target. */+ dimReused?: boolean;}-const { memoized = false, scenario, componentLabel } = Astro.props;+const {+ memoized = false, scenario, componentLabel,+ sourceLabel = 'Drive Folder', targetLabel = 'Vector Database',+ dimReused = false,+} = Astro.props;const defaultRows: RowEntry[] = [{ file: 'a.md', chunks: [@@ -114,9 +124,9 @@ const PC_X = FILE_X + FILE_W + FILE_TO_PC_GAP;title={`${componentLabel ?? 'Processing component'} with chunks`}desc={`Each file is split into chunks; ${componentLabel ?? 'the processing component'} produces one target state per chunk and syncs them as a unit.`}>- <LogicBox x={DRIVE.x} y={DRIVE.y} w={DRIVE.w} h={DRIVE.h} label="Drive Folder" />+ <LogicBox x={DRIVE.x} y={DRIVE.y} w={DRIVE.w} h={DRIVE.h} label={sourceLabel} /><AppContainer x={APP.x} y={APP.y} w={APP.w} h={APP.h} />- <LogicBox x={VDB.x} y={VDB.y} w={VDB.w} h={VDB.h} label="Vector Database" />+ <LogicBox x={VDB.x} y={VDB.y} w={VDB.w} h={VDB.h} label={targetLabel} />{rows.map((row, ri) => {const PC_H = rowLayouts[ri].h;@@ -135,6 +145,12 @@ const PC_X = FILE_X + FILE_W + FILE_TO_PC_GAP;...c,state: c.state ?? (row.pcState === 'removed' ? 'removed' : undefined),}));+ // A component with a cache hit did no work at all. In a component that+ // ran, an embedding with a cache hit and its target did not change.+ const dimRow = dimReused && row.pcStatus === 'cache-ready';+ const rowDim = dimRow ? 'dg-dim' : '';+ const reusedDim = (c: ChunkEntry) =>+ dimRow || (dimReused && c.embedStatus === 'cache-ready') ? 'dg-dim' : '';return (<g>@@ -147,9 +163,10 @@ const PC_X = FILE_X + FILE_W + FILE_TO_PC_GAP;x={FILE_X} y={fileY} w={FILE_W} h={FILE_H}label={row.file}state={row.fileState}+ class={rowDim}/>{/* file β Processing Component */}- <FlowArrow d={`M ${FILE_X + FILE_W} ${rowCY} L ${PC_X} ${rowCY}`} />+ <FlowArrow d={`M ${FILE_X + FILE_W} ${rowCY} L ${PC_X} ${rowCY}`} class={rowDim} /><ProcessingComponentx={PC_X} y={pcY} w={PC_W} h={PC_H}@@ -157,6 +174,7 @@ const PC_X = FILE_X + FILE_W + FILE_TO_PC_GAP;memoized={memoized}status={row.pcStatus}state={row.pcState}+ class={rowDim}><LogicBoxx={SPLIT_DX}@@ -165,6 +183,7 @@ const PC_X = FILE_X + FILE_W + FILE_TO_PC_GAP;h={SPLIT_H}label="Split into chunks"state={row.splitState}+ class={rowDim}/>{effectiveChunks.map((c, i) => {@@ -174,6 +193,7 @@ const PC_X = FILE_X + FILE_W + FILE_TO_PC_GAP;<g><FlowArrowd={`M ${SPLIT_DX + SPLIT_W} ${LOCAL_CY} C ${SPLIT_DX + SPLIT_W + 12} ${LOCAL_CY}, ${CHUNK_DX - 12} ${localCY}, ${CHUNK_DX} ${localCY}`}+ class={rowDim}/><DataBoxx={CHUNK_DX}@@ -181,8 +201,9 @@ const PC_X = FILE_X + FILE_W + FILE_TO_PC_GAP;w={CHUNK_W} h={CHUNK_H}label={c.label}state={c.state}+ class={rowDim}/>- <FlowArrow d={`M ${CHUNK_DX + CHUNK_W} ${localCY} L ${EMBED_DX} ${localCY}`} />+ <FlowArrow d={`M ${CHUNK_DX + CHUNK_W} ${localCY} L ${EMBED_DX} ${localCY}`} class={reusedDim(c)} /><LogicBoxx={EMBED_DX}y={localCY - EMBED_H / 2}@@ -191,14 +212,16 @@ const PC_X = FILE_X + FILE_W + FILE_TO_PC_GAP;memoized={memoized}status={c.embedStatus}state={c.state}+ class={reusedDim(c)}/>- <FlowArrow d={`M ${EMBED_DX + EMBED_W} ${localCY} L ${VECT_DX} ${localCY}`} />+ <FlowArrow d={`M ${EMBED_DX + EMBED_W} ${localCY} L ${VECT_DX} ${localCY}`} class={reusedDim(c)} /><TargetBulletx={VECT_DX}y={localCY - VECT_H / 2}w={VECT_W} h={VECT_H}label={c.vectorLabel}state={c.state}+ class={reusedDim(c)}/></g>);@@ -213,6 +236,7 @@ const PC_X = FILE_X + FILE_W + FILE_TO_PC_GAP;<Connectord={`M ${PC_X + VECT_DX + VECT_W} ${absCY} L ${VDB.x} ${absCY}`}dashed={true}+ class={reusedDim(c)}/>);})}diff --git a/docs/src/components/diagrams/concepts/SourcesToTargets.astro b/docs/src/components/diagrams/concepts/SourcesToTargets.astronew file mode 100644index 00000000..c5d9b111--- /dev/null+++ b/docs/src/components/diagrams/concepts/SourcesToTargets.astro@@ -0,0 +1,83 @@+---+/** Overview of `Target = F(Source)`: many kinds of source feed the functions+ that the reader writes, and the result lands in many kinds of target. The+ kinds follow the groups of the connectors index, which lists the chat source+ (Discord) and the document target (Google Docs) for the Python SDK only. */+import DiagramFrame from '../primitives/DiagramFrame.astro';+import DataBox from '../primitives/DataBox.astro';+import LogicBox from '../primitives/LogicBox.astro';+import TargetBullet from '../primitives/TargetBullet.astro';+import FlowArrow from '../primitives/FlowArrow.astro';++interface Props {+ /** The language of the reader's functions: it names the center box and+ selects the kinds that its SDK has connectors for. */+ language: 'Python' | 'Rust';+}+const { language } = Astro.props;+const python = language === 'Python';++const SOURCES = [+ 'Files and codebases', 'Object stores', 'Google Drive', 'Databases', 'Message streams',+ ...(python ? ['Chat'] : []),+];+const TARGETS = [+ 'Relational databases', 'Data warehouses', 'Vector databases',+ 'Graph databases', 'Message streams', python ? 'Files and documents' : 'Files',+];++// βββ Layout ββββββββββββββββββββββββββββββββββββββββ+const VB_W = 720;+const PAD_X = 16;+const HEAD_H = 30; // column headings+const ROW_H = 28, ROW_GAP = 10;+const COL_W = 176;+const ROWS = Math.max(SOURCES.length, TARGETS.length);+const COL_H = ROWS * ROW_H + (ROWS - 1) * ROW_GAP;+const TOP = HEAD_H + 6;+const VB_H = TOP + COL_H + 14;++const SRC_X = PAD_X;+const TGT_X = VB_W - PAD_X - COL_W;+const F_W = 176, F_H = 96;+const F_X = (VB_W - F_W) / 2;+const F_Y = TOP + (COL_H - F_H) / 2;++// A column with fewer rows than the other is centered against it. The three+// headings stay on one line.+const colDY = (n: number) => (ROWS - n) * (ROW_H + ROW_GAP) / 2;+const rowCY = (i: number, n: number) => TOP + colDY(n) + i * (ROW_H + ROW_GAP) + ROW_H / 2;+// The lines meet the center box along its edge, spread so that they do not pile up.+const EDGE_PAD = 14;+const edgeY = (i: number, n: number) => F_Y + EDGE_PAD + (i * (F_H - 2 * EDGE_PAD)) / (n - 1);+const bend = (x1: number, y1: number, x2: number, y2: number) => {+ const mx = (x1 + x2) / 2;+ return `M ${x1} ${y1} C ${mx} ${y1}, ${mx} ${y2}, ${x2} ${y2}`;+};+---+<DiagramFrame+ viewBox={`0 0 ${VB_W} ${VB_H}`}+ maxWidth={720}+ title="Sources, your functions, and targets"+ desc={`Sources (${SOURCES.join(', ')}) feed the ${language} functions that you write. Their result goes to targets (${TARGETS.join(', ')}).`}+>+ <text class="dg-label dg-label--caps" x={SRC_X + COL_W / 2} y={HEAD_H / 2}>Sources</text>+ <text class="dg-label dg-label--caps" x={VB_W / 2} y={HEAD_H / 2}>Your code</text>+ <text class="dg-label dg-label--caps" x={TGT_X + COL_W / 2} y={HEAD_H / 2}>Targets</text>++ {SOURCES.map((label, i) => (+ <g>+ <DataBox x={SRC_X} y={rowCY(i, SOURCES.length) - ROW_H / 2} w={COL_W} h={ROW_H} label={label} />+ <FlowArrow d={bend(SRC_X + COL_W, rowCY(i, SOURCES.length), F_X, edgeY(i, SOURCES.length))} />+ </g>+ ))}++ <LogicBox x={F_X} y={F_Y} w={F_W} h={F_H} label={`F\n${language} functions\nthat you write`} />++ {TARGETS.map((label, j) => (+ <g>+ <FlowArrow d={bend(F_X + F_W, edgeY(j, TARGETS.length), TGT_X, rowCY(j, TARGETS.length))} />+ <TargetBullet x={TGT_X} y={rowCY(j, TARGETS.length) - ROW_H / 2} w={COL_W} h={ROW_H} label={label} />+ </g>+ ))}+</DiagramFrame>diff --git a/docs/src/components/diagrams/concepts/UseCaseArt.astro b/docs/src/components/diagrams/concepts/UseCaseArt.astroindex 05c38646..fb652487 100644--- a/docs/src/components/diagrams/concepts/UseCaseArt.astro+++ b/docs/src/components/diagrams/concepts/UseCaseArt.astro@@ -7,7 +7,7 @@import '../diagrams.css';interface Props {- kind: 'search' | 'code' | 'graph' | 'extract' | 'table' | 'stream';+ kind: 'search' | 'graph' | 'extract' | 'fanout' | 'stages' | 'sources';}const { kind } = Astro.props;@@ -22,6 +22,14 @@ const NODES = [];const DELTA_NODE = { x: 192, y: 98, r: 9 };const SIDE_EDGES = [[0, 2], [2, 3], [0, 1]];++// High fan-out: the tops of the target rows, and the one row that a change touches.+const FAN_ROWS = [14, 34, 54, 74, 94, 114];+const FAN_DELTA = 2;++// Multi-stage: the raw mentions on the left, and where each one enters the resolve box.+const MENTIONS = [35, 55, 75, 95];+const RESOLVE_IN = [60, 68, 76, 84];---<svg class="uc-art" viewBox="0 0 240 144" aria-hidden="true">{kind === 'search' && (@@ -46,25 +54,6 @@ const SIDE_EDGES = [[0, 2], [2, 3], [0, 1]];</g>)}- {kind === 'code' && (- <g>- {/* a source file; one function is one chunk */}- <rect class="dg-box" x="34" y="12" width="172" height="120" rx="8" />- <circle class="uc-dot" cx="47" cy="23" r="2.5" />- <circle class="uc-dot" cx="56" cy="23" r="2.5" />- <circle class="uc-dot" cx="65" cy="23" r="2.5" />- <path class="uc-rule" d="M34 34 H206" />-- <rect class="uc-bar" x="46" y="44" width="62" height="5" rx="2.5" />- <g class="dg-state-new"><rect class="dg-box" x="52" y="56" width="142" height="40" rx="5" /></g>- <rect class="uc-bar uc-bar--delta" x="60" y="63" width="70" height="5" rx="2.5" />- <rect class="uc-bar uc-bar--delta" x="70" y="73.5" width="98" height="5" rx="2.5" />- <rect class="uc-bar uc-bar--delta" x="70" y="84" width="52" height="5" rx="2.5" />- <rect class="uc-bar" x="46" y="104" width="86" height="5" rx="2.5" />- <rect class="uc-bar" x="58" y="115" width="112" height="5" rx="2.5" />- </g>- )}-{kind === 'graph' && (<g>{/* entities and relationships; one entity and its edge are new */}@@ -107,51 +96,85 @@ const SIDE_EDGES = [[0, 2], [2, 3], [0, 1]];</g>)}- {kind === 'table' && (+ {kind === 'fanout' && (<g>- {/* a source table, and a target table with one derived column */}- <rect class="dg-box" x="20" y="34" width="72" height="76" rx="6" />- <path class="uc-rule" d="M20 53 H92 M20 72 H92 M20 91 H92 M56 34 V110" />- {[0, 1, 2, 3].map((r) => (- <g>- <rect class="uc-bar" x="28" y={41 + r * 19} width={[18, 20, 14, 22][r]} height="5" rx="2.5" />- <rect class="uc-bar" x="64" y={41 + r * 19} width={[20, 14, 22, 16][r]} height="5" rx="2.5" />- </g>+ {/* one source item, many target rows; a change touches one of them */}+ <path class="dg-box" d="M24 34 a6 6 0 0 1 6 -6 H62 L78 44 V110 a6 6 0 0 1 -6 6 H30 a6 6 0 0 1 -6 -6 Z" />+ <path class="uc-line" d="M62 28 V44 H78" />+ <rect class="uc-bar" x="33" y="54" width="30" height="5" rx="2.5" />+ <rect class="uc-bar" x="33" y="66" width="36" height="5" rx="2.5" />+ <rect class="uc-bar" x="33" y="78" width="26" height="5" rx="2.5" />+ <rect class="uc-bar" x="33" y="90" width="34" height="5" rx="2.5" />++ {FAN_ROWS.map((y, i) => (+ <path class:list={['uc-line', { 'uc-line--delta': i === FAN_DELTA }]} d={`M78 72 C104 72 104 ${y + 7} 130 ${y + 7}`} />))}-- <path class="uc-line" d="M102 72 H126 M121 67 L126 72 L121 77" />-- <rect class="dg-box" x="136" y="34" width="86" height="76" rx="6" />- <g class="dg-state-new"><path class="dg-box" d="M194 34 H216 a6 6 0 0 1 6 6 V104 a6 6 0 0 1 -6 6 H194 Z" /></g>- <path class="uc-rule" d="M136 53 H194 M136 72 H194 M136 91 H194 M165 34 V110" />- {[0, 1, 2, 3].map((r) => (- <g>- <rect class="uc-bar" x="143" y={41 + r * 19} width={[14, 16, 12, 16][r]} height="5" rx="2.5" />- <rect class="uc-bar" x="172" y={41 + r * 19} width={[16, 12, 16, 14][r]} height="5" rx="2.5" />- <rect class="uc-bar uc-bar--delta" x="201" y={41 + r * 19} width="14" height="5" rx="2.5" />- </g>+ {FAN_ROWS.map((y, i) => (+ i === FAN_DELTA+ ? <g>+ <g class="dg-state-new"><rect class="dg-box" x="130" y={y} width="88" height="14" rx="3" /></g>+ <rect class="uc-bar uc-bar--delta" x="138" y={y + 4.5} width="52" height="5" rx="2.5" />+ </g>+ : <g>+ <rect class="dg-box" x="130" y={y} width="88" height="14" rx="3" />+ <rect class="uc-bar" x="138" y={y + 4.5} width={[44, 60, 0, 36, 56, 48][i]} height="5" rx="2.5" />+ </g>))}</g>)}- {kind === 'stream' && (+ {kind === 'stages' && (<g>- {/* messages on a topic; each one goes to the store that matches it */}- <path class="uc-rule" d="M18 72 H132" />- <rect class="dg-box" x="20" y="64" width="24" height="16" rx="8" />- <rect class="dg-box" x="50" y="64" width="24" height="16" rx="8" />- <rect class="dg-box" x="80" y="64" width="24" height="16" rx="8" />- <g class="dg-state-new"><rect class="dg-box" x="110" y="64" width="24" height="16" rx="8" /></g>-- <path class="uc-line uc-line--delta" d="M138 72 C154 72 152 40 168 40 M163 35.5 L168 40 L162.5 44" />- <path class="uc-line" d="M138 72 C154 72 152 104 168 104 M162.5 100 L168 104 L163 108.5" />-- <g class="dg-state-new">- <path class="dg-box" d="M174 32 V50 a22 6 0 0 0 44 0 V32" />- <ellipse class="dg-box" cx="196" cy="32" rx="22" ry="6" />- </g>- <path class="dg-box" d="M174 96 V114 a22 6 0 0 0 44 0 V96" />- <ellipse class="dg-box" cx="196" cy="96" rx="22" ry="6" />+ {/* stage 1: raw mentions; stage 2: resolve them; stage 3: link them in a graph */}+ {MENTIONS.map((y) => <rect class="dg-box" x="16" y={y} width="46" height="14" rx="7" />)}+ {MENTIONS.map((y, i) => (+ <path class="uc-line" d={`M62 ${y + 7} C78 ${y + 7} 78 ${RESOLVE_IN[i]} 94 ${RESOLVE_IN[i]}`} />+ ))}++ <rect class="dg-box" x="94" y="42" width="52" height="60" rx="8" />+ <path class="uc-line" d="M104 56 L132 72 M104 72 H132 M104 88 L132 72" />+ <circle class="uc-dot" cx="104" cy="56" r="3" />+ <circle class="uc-dot" cx="104" cy="72" r="3" />+ <circle class="uc-dot" cx="104" cy="88" r="3" />+ <g class="dg-state-new"><circle class="dg-box" cx="133" cy="72" r="5" /></g>++ <path class="uc-line" d="M152 72 H170 M165 67 L170 72 L165 77" />++ <path class="uc-line" d="M184 46 L216 72 M184 98 L216 72 M184 46 V98" />+ <path class="uc-line uc-line--delta" d="M184 46 L216 72" />+ <circle class="dg-box" cx="184" cy="98" r="8" />+ <circle class="dg-box" cx="216" cy="72" r="8" />+ <g class="dg-state-new"><circle class="dg-box" cx="184" cy="46" r="8" /></g>+ </g>+ )}+ {kind === 'sources' && (+ <g>+ {/* three kinds of source feed one target; a change in one source touches its own rows */}+ <path class="dg-box" d="M24 16 a5 5 0 0 1 5 -5 H50 L60 21 V45 a5 5 0 0 1 -5 5 H29 a5 5 0 0 1 -5 -5 Z" />+ <path class="uc-line" d="M50 11 V21 H60" />+ <rect class="uc-bar" x="31" y="28" width="20" height="4" rx="2" />+ <rect class="uc-bar" x="31" y="37" width="14" height="4" rx="2" />++ <g class="dg-state-new"><rect class="dg-box" x="20" y="58" width="44" height="30" rx="5" /></g>+ <path class="uc-rule" d="M20 68 H64 M20 78 H64 M42 58 V88" />++ <path class="dg-box" d="M22 104 V122 a20 5 0 0 0 40 0 V104" />+ <ellipse class="dg-box" cx="42" cy="104" rx="20" ry="5" />++ <path class="uc-line" d="M60 31 C98 31 98 66 132 66" />+ <path class="uc-line uc-line--delta" d="M64 73 H132 M127 68 L132 73 L127 78" />+ <path class="uc-line" d="M62 115 C98 115 98 80 132 80" />++ <rect class="dg-box" x="140" y="28" width="82" height="90" rx="6" />+ {[0, 1, 2, 3, 4].map((r) => (+ r === 2+ ? <g>+ <g class="dg-state-new"><rect class="dg-box" x="140" y="64" width="82" height="18" /></g>+ <rect class="uc-bar uc-bar--delta" x="150" y="70.5" width="52" height="5" rx="2.5" />+ </g>+ : <rect class="uc-bar" x="150" y={34.5 + r * 18} width={[44, 58, 0, 36, 50][r]} height="5" rx="2.5" />+ ))}+ <path class="uc-rule" d="M140 46 H222 M140 100 H222" /></g>)}</svg>diff --git a/docs/src/components/diagrams/diagrams.css b/docs/src/components/diagrams/diagrams.cssindex 172c0bd2..ba1d4814 100644--- a/docs/src/components/diagrams/diagrams.css+++ b/docs/src/components/diagrams/diagrams.css@@ -227,6 +227,17 @@fill: color-mix(in oklab, var(--pink) 10%, var(--cream));}+/* βββ Dimmed: work that this run did not repeat βββββββββββββββ+ Opt-in (`dimReused` on ComponentWithChunks). Direct children only, so+ the status badge on the same group keeps its full strength. */+.dg-dim>.dg-box,+.dg-dim>foreignObject,+.dg-dim>.dg-memo,+.dg-dim>.dg-flow,+.dg-connector.dg-dim {+ opacity: 0.5;+}+/* βββ Flow arrows βββββββββββββββββββββββββββββββββββββββββββ */.dg-flow {diff --git a/docs/src/components/diagrams/primitives/StatusBadge.astro b/docs/src/components/diagrams/primitives/StatusBadge.astroindex d85582d1..2c376a31 100644--- a/docs/src/components/diagrams/primitives/StatusBadge.astro+++ b/docs/src/components/diagrams/primitives/StatusBadge.astro@@ -44,7 +44,9 @@ const checkD = `M ${-r * 0.45} 0 L ${-r * 0.1} ${r * 0.35} L ${r * 0.5} ${-r * 0<g><title>refreshing β re-executing</title><circle class="dg-status-bg" cx="0" cy="0" r={r} />- {/* spinning arrow: a 3/4 circular arc with a triangular arrowhead */}+ {/* spinning arrow: a 3/4 circular arc that runs clockwise from 6 o'clock+ to 3 o'clock, with a triangular arrowhead at its end. The head points+ down, into the open quarter, so that the still badge reads as an arrow. */}<g class="dg-status-spin"><pathclass="dg-status-mark"@@ -55,7 +57,7 @@ const checkD = `M ${-r * 0.45} 0 L ${-r * 0.1} ${r * 0.35} L ${r * 0.5} ${-r * 0/><polygonclass="dg-status-mark"- points={`${r * 0.82},${r * 0.15} ${r * 0.28},${r * 0.15} ${r * 0.55},${-r * 0.3}`}+ points={`${r * 0.92},${-r * 0.14} ${r * 0.18},${-r * 0.14} ${r * 0.55},${r * 0.44}`}/></g></g>diff --git a/docs/src/content/docs/getting_started/overview.mdx b/docs/src/content/docs/getting_started/overview.mdxindex f7655047..aa587a41 100644--- a/docs/src/content/docs/getting_started/overview.mdx+++ b/docs/src/content/docs/getting_started/overview.mdx@@ -9,45 +9,63 @@ rust_description: >with a source that changes. This page shows the problem it solves, the Rust code youwrite, and where it fits.---+import Formula from '/src/components/Formula.astro';import ComponentWithChunks from '/src/components/diagrams/concepts/ComponentWithChunks.astro';+import SourcesToTargets from '/src/components/diagrams/concepts/SourcesToTargets.astro';import UseCaseGrid from '/src/components/UseCaseGrid.astro';import UseCase from '/src/components/UseCase.astro';+import Mark from '/src/components/Mark.astro';-CocoIndex builds materialized views over data that changes, structured or unstructured.-A materialized view is a stored result that a system keeps in sync with the data it came from.+CocoIndex turns data from your sources, structured or unstructured, into the form that your AI needs.+It does this continuously: when a source changes, CocoIndex updates the result.-- The **target** is the view. It is usually context for an AI agent or application: a search index, a knowledge graph, or tables. It is in your own store, such as Postgres or a vector database, and your application queries it there.-- The **source** is a codebase, a folder of documents, chat messages, or rows in a database.+- The **source** is the data that you start from. For example: a codebase, a folder of documents, web pages, chat messages, or rows in a database.+- The **target** is the data that you derive from the source. It is usually context for an AI agent or application: a search index, a knowledge graph, or tables. It is in your own store, such as Postgres or a vector database, and your application queries it there.-You define the view in <Lang only="python">Python</Lang><Lang only="rust">Rust</Lang> instead of SQL:+You write the transformation, and CocoIndex keeps the target in sync with the source.+Two familiar systems work in the same way:++- A materialized view in a database is a stored query result. Some databases keep it up to date as the tables change.+- In React, you declare the UI as a function of the state, and React updates what changed.++In CocoIndex, you define the target as a function of the source, in <Lang only="python">Python</Lang><Lang only="rust">Rust</Lang> instead of SQL:++<Formula>**Target = F(Source)**+</Formula>+`F` is a set of <Lang only="python">Python</Lang><Lang only="rust">Rust</Lang> functions that you write, with your own libraries and control flow.-CocoIndex keeps the target up to date when the source changes, and when `F` changes.+CocoIndex updates the target when the source changes, and when `F` changes.-## What people build with it+<Lang only="python">-<UseCaseGrid>-<UseCase art="search">+<SourcesToTargets language="Python" />-**Search and RAG indexes**+</Lang>-Chunk and embed documents into a vector store. An edit replaces only the chunks that changed.+<Lang only="rust">-Example: [Semantic search 101](/docs/examples/text-embedding/)+<SourcesToTargets language="Rust" />-</UseCase>-<UseCase art="code">+</Lang>++## What people build with it-**Code indexes for coding agents**+The first three cards are kinds of target. The last three are patterns that a pipeline can have.++<UseCaseGrid>+<UseCase art="search" label="Target">++**Search and RAG indexes**-Split code along its syntax and embed it. A commit runs only the files that changed.+Chunk and embed documents or code into a vector store. An edit replaces only the chunks that changed.-Example: [Index your codebase for AI agents](/docs/examples/index-codebase/)+Examples: [Semantic search 101](/docs/examples/text-embedding/) and [Index your codebase for AI agents](/docs/examples/index-codebase/)</UseCase>-<UseCase art="graph">+<UseCase art="graph" label="Target">**Knowledge graphs**@@ -56,88 +74,95 @@ Extract entities and relationships with an LLM into a graph database. Only an edExample: [Turn meeting notes into a knowledge graph](/docs/examples/meeting-notes-to-knowledge-graph/)</UseCase>-<UseCase art="extract">+<UseCase art="extract" label="Target">**Structured extraction**-Turn PDFs, forms and transcripts into typed rows with an LLM. A run skips the documents that did not change.+Turn PDFs, forms and transcripts into typed records with an LLM. A run skips the documents that did not change.Example: [Patient intake extraction](/docs/examples/patient-intake-dspy/)</UseCase>-<UseCase art="table">+<UseCase art="fanout" label="Pattern">-**Derived tables**+**High fan-out**-Read rows from a database, derive new fields, and write them to a table or a vector store. Only the rows that changed run again.+One source item can produce many target items. For example, one PDF becomes many pages, and each page gets its own vectors. After an edit, CocoIndex writes only the items that changed.-Example: [Postgres as a source](/docs/examples/postgres-source/)+Example: [Index any format together](/docs/examples/multi-format-indexing/)</UseCase>-<UseCase art="stream">+<UseCase art="stages" label="Pattern">-**Message streams**+**Multi-stage pipelines**-Consume a Kafka topic as keyed messages, and write each message to a table chosen by its fields. A newer message for a key updates its row, and a tombstone deletes it.+Chain steps where one step feeds the next: extract entities, resolve duplicates, then link them in a graph. A step can cache its results, and CocoIndex reuses them when its inputs are unchanged.-Example: [Consume Kafka into LanceDB](/docs/examples/kafka-to-lancedb/)+Example: [Turn podcasts into a knowledge graph](/docs/examples/podcast-to-knowledge-graph/)</UseCase>-</UseCaseGrid>+<UseCase art="sources" label="Pattern">++**Multi-source pipelines**++Read several sources in one app, with a function for each source, and merge the results into one target. When one source changes, CocoIndex processes only the changed items of that source.-The [examples](/docs/examples/) page has more.<Lang only="rust"> The examples there are in Python. Many of them have a Rust port in [`examples/rust`](https://github.com/cocoindex-io/cocoindex/tree/main/examples/rust).</Lang>+Example: [SEC filing hybrid search](/docs/examples/sec-edgar-analytics/)-## The second run is the hard one+</UseCase>+</UseCaseGrid>-The first version of a pipeline is short. It reads each item, transforms it, and writes the result.-That version is correct once. After that, the source changes, and so does your code.+A source can be structured too: see [Postgres as a source](/docs/examples/postgres-source/) and [Consume Kafka into LanceDB](/docs/examples/kafka-to-lancedb/). The [examples](/docs/examples/) page has more.<Lang only="rust"> The examples there are in Python. Many of them have a Rust port in [`examples/rust`](https://github.com/cocoindex-io/cocoindex/tree/main/examples/rust).</Lang>-One way to keep the target current is to rebuild everything on a schedule.-Each rebuild runs every embedding and every LLM call again, and the data is stale between rebuilds.+## A pipeline without CocoIndex-The other way is to make the pipeline incremental yourself. Your code then has five more jobs.+A stateless pipeline reads each item, transforms it, and writes the result.+It keeps no record of earlier runs, and it has no logic for changes.+It is enough for the first run. After that, the source changes, and so does your code.+Without CocoIndex, you have two ways to keep the target current.-**1. Turn each source change into the right target changes.**-One source item usually produces several target items.-For example, one document becomes many chunks, and each chunk is one row.+### Option 1: reprocess everything-| The source change | What your code must do to the target |-|---|---|-| A new document | Insert one row for each chunk. |-| An edited document | Compare the new chunks with the old rows. Insert some rows, update some, delete some, and leave the rest. |-| A deleted document | Find every row that came from the document, and delete it. |+You run the whole pipeline again on a schedule, and replace the target.+Each run repeats every embedding and every LLM call. That costs tokens and time, and API rate limits can slow it further.+The cost limits how often you can run it, and the target is stale between runs.-For an edit or a delete, your code must know which rows each document produced before.-It therefore needs a record of the earlier runs.+### Option 2: make the pipeline incremental yourself-**2. Handle a change to your own code.**-A new prompt, chunk size or model makes existing rows out of date.-Your code must find those rows, compute them again, and replace them.-A new field in a row also changes the table.+You make the pipeline stateful. Your code manages the processing state itself, and updates only what changed.+That code has six jobs. For each job, the table shows what your code must do, and which part of CocoIndex does it instead.+The example is a pipeline that splits files into chunks, and writes one row for each chunk. The names in the last column are from its code in the next section.-**3. Find the changes, completely and quickly.**-A scan finds every change, but it takes time, so the target is stale between scans.-Change events, such as file system notifications or a database change feed, arrive immediately. But the pipeline sees them only while it runs.-A pipeline that needs fresh data needs both, and both must run the same processing logic.+| Job | Without CocoIndex, your code must | With CocoIndex |+|---|---|---|+| **1. Turn each source change into the right target changes** | Keep a record of the rows that each file produced. For an edited file, compare the new chunks with the old rows, then insert, update and delete rows. For a deleted file, find its rows and delete them. | <Lang only="python">[`mount_each()`](../programming_guide/processing_component#mount_each)</Lang><Lang only="rust">`mount_each_live()`</Lang> tracks what each file declares. [`declare_row()`](../programming_guide/target_state) states the rows, and CocoIndex computes the inserts, updates and deletes. |+| **2. Handle a change to your own code** | Find the rows that a new prompt, chunk size or model made out of date, and compute them again. | With <Lang only="python">[`memo=True`](../programming_guide/function#memoization)</Lang><Lang only="rust">[`memo`](../programming_guide/function#memoization)</Lang>, a function runs again only when its input, its code, or a tracked context value (such as the model) changes. |+| **3. Keep the target schema in sync with your code** | Write `CREATE TABLE`, with a column type for each field of a row. Keep the types in sync with your code, such as the vector size of the embedding model. For each change to the fields, write and run `ALTER TABLE`. | <Lang only="python">`mount_table_target()`</Lang><Lang only="rust">`postgres::mount_table_target()`</Lang> declares the table, with columns from your row <Lang only="python">class</Lang><Lang only="rust">struct</Lang>. CocoIndex creates the table, and [alters it](../programming_guide/target_state#what-happens-when-a-targets-schema-changes) when the <Lang only="python">class</Lang><Lang only="rust">struct</Lang> changes. |+| **4. Find the changes, completely and quickly** | Scan the source, so that you miss no change. Read change events, such as file notifications or a database change feed, so that changes arrive quickly. Run the same logic on both paths. | `cocoindex update` scans the source. With `-L`, it also [keeps watching](../programming_guide/live_mode) a source that has <Lang only="python">`live=True`</Lang><Lang only="rust">`.live()`</Lang>. Both paths run the same functions. |+| **5. Do not repeat expensive work** | Cache each embedding and each LLM result. | The built-in `embed()` caches its results, and <Lang only="python">`memo=True`</Lang><Lang only="rust">`memo`</Lang> caches your own functions. |+| **6. Recover from a run that stops halfway** | Find which writes completed, and finish or repair the rest. | Run it again. CocoIndex [brings the table to the declared state](../advanced_topics/exception_handlers#interrupted-updates-and-recovery). |-**4. Do not repeat expensive work.**-The pipeline needs a cache for each embedding and each LLM result, so that unchanged text costs nothing.+## The same pipeline with CocoIndex-**5. Recover from a run that stops halfway.**-The target is then between two states. Your code must find which writes completed, and finish or repair the rest.+With CocoIndex, your code stays as simple as the stateless pipeline, and CocoIndex does the incremental processing.-With CocoIndex, your code stays close to the first version. It reads, transforms, and declares the result.-CocoIndex records what each run did, in a local database. The next run uses that record to do only the work that a change requires.+| | Option 1: reprocess everything | Option 2: incremental by hand | With CocoIndex |+|---|---|---|---|+| **Code that you write** | <Mark good>β</Mark> Simple: the stateless pipeline | <Mark bad>β</Mark> Complex: a stateful pipeline. You manage the processing state yourself, with the [six jobs above](#option-2-make-the-pipeline-incremental-yourself) | <Mark good>β</Mark> Simple: the stateless pipeline, plus a few declarations |+| **Processing in each run** | <Mark bad>β</Mark> Every item, every model call | <Mark good>β</Mark> Only what a change requires | <Mark good>β</Mark> Only what a change requires |+| **The target** | <Mark bad>β</Mark> Stale: a full run costs too much to repeat often | <Mark good>β</Mark> Current: quick runs, or change events | <Mark good>β</Mark> Current: quick runs, or [live mode](../programming_guide/live_mode) |-## What you write+Your code reads, transforms, and declares the result.+CocoIndex keeps the state: it records what each run did, in an embedded database. The next run uses that record to do only the work that a change requires.+That run is quick when few items changed, so you can run it often. Live mode keeps the app running, and applies changes as they arrive.-This pipeline builds a search index over a folder of Markdown files.+The example below builds a search index over a folder of Markdown files.It splits each file into chunks, embeds each chunk, and keeps one row for each chunk in a Postgres table.<Lang only="python">-The code is a shortened version of the [text embedding example](https://github.com/cocoindex-io/cocoindex/tree/main/examples/text_embedding).-It leaves out the imports and the row class. It also leaves out the setup of the Postgres connection (`PG_DB`), the embedding model (`EMBEDDER`) and the text splitter (`_splitter`).+The code is a simplified version of the [text embedding example](https://github.com/cocoindex-io/cocoindex/tree/main/examples/text_embedding).+It leaves out the imports. It also leaves out the setup of the Postgres connection (`PG_DB`), the embedding model (`EMBEDDER`) and the text splitter (`_splitter`).</Lang>@@ -148,11 +173,25 @@ It leaves out the imports, the row type and the table setup. It also leaves out</Lang>+The code has three parts:++1. **Connect a source.** <Lang only="python">`localfs.walk_dir()` lists the Markdown files. With `live=True`, it can also watch the folder.</Lang><Lang only="rust">`walk_dir()` lists the Markdown files. With `.live()`, it can also watch the folder.</Lang>+2. **Write the processing logic.** `process_file` handles one file. It splits the text, embeds each chunk, and declares one row for each chunk. <Lang only="python">`mount_each()`</Lang><Lang only="rust">`mount_each_live()`</Lang> runs it once for each file. <Lang only="python">`memo=True`</Lang><Lang only="rust">`memo`</Lang> lets CocoIndex skip a file that did not change, and the built-in `embed()` caches each embedding.+3. **Declare the target.** <Lang only="python">The `DocChunk` class defines the columns. `mount_table_target()` declares the table, and `declare_row()` declares each row.</Lang><Lang only="rust">`declare_row()` declares each row. The full example declares the table with `postgres::mount_table_target()`.</Lang> `IdGenerator` gives an unchanged chunk the same id in every run, so its row stays as it is. CocoIndex does the writes.+{/* Rust: examples/rust/text_embedding/src/main.rs (process_chunk and process_file as they are there, without the doc comments; the end of index(), without the comments) */}<LangTabs><Fragment slot="python">```python title="main.py"+@dataclass+class DocChunk:+ id: int+ filename: str+ text: str+ embedding: Annotated[NDArray, EMBEDDER]++@coco.fn(memo=True)async def process_file(file: FileLike, table: postgres.TableTarget[DocChunk]) -> None:text = await file.read_text()@@ -191,7 +230,7 @@ app = coco.App("DocSearch", app_main, sourcedir=pathlib.Path("./docs"))</Fragment><Fragment slot="rust">-```rust+```rust title="src/main.rs"#[cocoindex::function]async fn process_chunk(ctx: &Ctx,@@ -239,9 +278,9 @@ async fn process_file(ctx: &Ctx, file: &FileEntry, table: &postgres::TableTarget}```-The main function lists the files and runs `process_file` for each one:+The `index` function lists the files and runs `process_file` for each one:-```rust+```rust title="src/main.rs"let files = walk_dir(sourcedir).recursive(true).path_matcher(PatternFilePathMatcher::include(["**/*.md"])?)@@ -257,43 +296,62 @@ ctx.mount_each_live(&"process_file", files, move |ctx, file: FileEntry| {</Fragment></LangTabs>-<Lang only="python">`process_file` is still a loop over the chunks of one file. The last line makes the pipeline an app that the `cocoindex` command can run. </Lang>The code has no logic for the five jobs. A few declarations hand each job to CocoIndex:+<Lang only="python">`process_file` is still a loop over the chunks of one file. The last line makes the pipeline an app, and `cocoindex update main.py` runs it. </Lang>The code declares what the target contains. It has no logic for the six jobs.-1. **Target changes.** `declare_row()` states that a row must [exist in the target](../programming_guide/target_state), and writes nothing yet. <Lang only="python">`mount_table_target()` states the same for the table.</Lang><Lang only="rust">In the full example, `postgres::mount_table_target()` states the same for the table.</Lang> <Lang only="python">`mount_each()`</Lang><Lang only="rust">`mount_each_live()`</Lang> *mounts* `process_file` for each file: CocoIndex calls it once for that file and tracks what it declares. CocoIndex therefore knows which rows belong to which file.-2. **Code changes.** <Lang only="python">`memo=True`</Lang><Lang only="rust">`memo`</Lang> keeps the rows that `process_file` declared for each file. CocoIndex reuses them while the file and the code are unchanged. When either one changes, it calls `process_file` again.-3. **Finding changes.** <Lang only="python">`cocoindex update main.py`</Lang><Lang only="rust">`cocoindex update`</Lang> scans the folder and exits. With `-L`, it scans the folder and then [keeps watching](../programming_guide/live_mode). <Lang only="python">`live=True`</Lang><Lang only="rust">`.live()`</Lang> makes the file listing able to watch, and has no effect without `-L`.-4. **Repeated work.** The built-in `embed()` caches its results, and <Lang only="python">`memo=True`</Lang><Lang only="rust">`memo`</Lang> does the same for your own functions. `IdGenerator` gives each chunk a [stable id](../common_resources/id_generation). An unchanged chunk therefore costs no model call and no write.-5. **Failures.** One failed file does not stop the other files. After a crash, you start the run again, and it [brings the table to the declared state](../advanced_topics/exception_handlers#interrupted-updates-and-recovery).+Suppose that the folder has two files, `a.md` and `b.md`, and that each file has two chunks.+After the first run, the target has four rows:++<ComponentWithChunks memoized={true} componentLabel="process_file" sourceLabel="Markdown folder" targetLabel="Postgres table" scenario={{ rows: [+ { file: 'a.md', chunks: [+ { label: 'chunk1', vectorLabel: 'row1' },+ { label: 'chunk2', vectorLabel: 'row2' },+ ] },+ { file: 'b.md', chunks: [+ { label: 'chunk3', vectorLabel: 'row3' },+ { label: 'chunk4', vectorLabel: 'row4' },+ ] },+]}} />++The ribbon marks a memoized function, one that caches its results: `process_file` for each file, and `embed()` for each chunk.## What CocoIndex does when something changesTwo things change over time: the source data and your code.Either one can require changes to rows (insert, update, delete) and to the table itself (create, alter, drop).-CocoIndex works them out from what your functions declare.+CocoIndex computes them from what your functions declare.-The diagrams use the example above with two files, `a.md` and `b.md`.-Each file has two chunks.+The two diagrams below start from the state after the first run, shown above.+Dimmed parts did no work in this run.+A check mark means that CocoIndex reused an earlier result. A circular arrow means that it ran the function again.+A highlighted box is new or changed, and a dashed box is removed.### The source changesSomeone edits `b.md`, and the edit changes its second chunk.-<ComponentWithChunks memoized={true} componentLabel="process_file" scenario={{ rows: [+<ComponentWithChunks memoized={true} dimReused={true} componentLabel="process_file" sourceLabel="Markdown folder" targetLabel="Postgres table" scenario={{ rows: [{ file: 'a.md', pcStatus: 'cache-ready', chunks: [- { label: 'chunk1', vectorLabel: 'vector1', embedStatus: 'cache-ready' },- { label: 'chunk2', vectorLabel: 'vector2', embedStatus: 'cache-ready' },+ { label: 'chunk1', vectorLabel: 'row1' },+ { label: 'chunk2', vectorLabel: 'row2' },] },- { file: 'b.md', fileState: 'updated', pcStatus: 'refreshing', pcState: 'updated', splitState: 'updated', chunks: [- { label: 'chunk3', vectorLabel: 'vector3', embedStatus: 'cache-ready' },- { label: 'chunk4', vectorLabel: 'vector4', state: 'removed' },- { label: 'chunk5', vectorLabel: 'vector5', state: 'new' },+ { file: 'b.md', fileState: 'updated', pcStatus: 'refreshing', chunks: [+ { label: 'chunk3', vectorLabel: 'row3', embedStatus: 'cache-ready' },+ { label: 'chunk4', vectorLabel: 'row4', state: 'removed' },+ { label: 'chunk5', vectorLabel: 'row5', state: 'new' },] },]}} />+| | Files processed | Embeddings computed | Rows replaced |+|---|---|---|---|+| **This run with CocoIndex** | 1 | 1 | 1 |+| **Reprocess everything** | 2 | 4 | 4 |++The numbers for CocoIndex stay the same when the folder has 1,000 files. The numbers for a full reprocess grow with the folder.+- `a.md` is unchanged, so CocoIndex skips `process_file` for it and keeps its rows.- CocoIndex calls `process_file` again for `b.md`.-- The first chunk of `b.md` has the same text. Its embedding comes from the cache, and only the new chunk goes to the model.-- When `process_file` finishes, CocoIndex compares the rows that `b.md` declares now with its rows from the last run. It deletes the row of the old chunk and inserts the row of the new chunk. It does not write the other row again.+- `chunk3` has the same text as before. Its embedding comes from the cache, and only `chunk5` goes to the model.+- When `process_file` finishes, CocoIndex compares the rows that `b.md` declares now with its rows from the last run. It deletes `row4` and inserts `row5`. It does not write `row3` again.When someone deletes `b.md`, the listing no longer contains it, and CocoIndex deletes the rows that came from it.For a new file, CocoIndex calls `process_file` and inserts the rows.@@ -303,46 +361,53 @@ For a new file, CocoIndex calls `process_file` and inserts the rows.You change how `process_file` splits the text.With the new rule, `a.md` still splits into the same chunks, and `b.md` splits into different chunks.-<ComponentWithChunks memoized={true} componentLabel="process_file" scenario={{ rows: [+<ComponentWithChunks memoized={true} dimReused={true} componentLabel="process_file" sourceLabel="Markdown folder" targetLabel="Postgres table" scenario={{ rows: [{ file: 'a.md', pcStatus: 'refreshing', pcState: 'updated', splitState: 'updated', chunks: [- { label: 'chunk1', vectorLabel: 'vector1', embedStatus: 'cache-ready' },- { label: 'chunk2', vectorLabel: 'vector2', embedStatus: 'cache-ready' },+ { label: 'chunk1', vectorLabel: 'row1', embedStatus: 'cache-ready' },+ { label: 'chunk2', vectorLabel: 'row2', embedStatus: 'cache-ready' },] },{ file: 'b.md', pcStatus: 'refreshing', pcState: 'updated', splitState: 'updated', chunks: [- { label: 'chunk3', vectorLabel: 'vector3', state: 'removed' },- { label: 'chunk4', vectorLabel: 'vector4', state: 'removed' },- { label: 'chunk5', vectorLabel: 'vector5', state: 'new' },- { label: 'chunk6', vectorLabel: 'vector6', state: 'new' },+ { label: 'chunk3', vectorLabel: 'row3', state: 'removed' },+ { label: 'chunk4', vectorLabel: 'row4', state: 'removed' },+ { label: 'chunk5', vectorLabel: 'row5', state: 'new' },+ { label: 'chunk6', vectorLabel: 'row6', state: 'new' },] },]}} />+| | Files processed | Embeddings computed | Rows replaced |+|---|---|---|---|+| **This run with CocoIndex** | 2 | 2 | 2 |+| **Reprocess everything** | 2 | 4 | 4 |++CocoIndex processes both files again, but the splitting is cheap. The model calls are the expensive part, and CocoIndex makes 2 of the 4.+- The code of `process_file` changed, so CocoIndex calls it again for both files.- `a.md` produces the same chunks as before. CocoIndex reuses their embeddings, and the rows of `a.md` stay as they are.- `b.md` produces two different chunks. CocoIndex embeds them, deletes the two old rows, and inserts two new rows.You write no backfill script for this change.-A code change can also change the table. For a new field in the row, CocoIndex [alters the table](../programming_guide/target_state#what-happens-when-a-targets-schema-changes) and fills the new column.+A code change can also change the table. For a new field in the row, CocoIndex [alters the table](../programming_guide/target_state#what-happens-when-a-targets-schema-changes). The new run of `process_file` fills the new column.[Change detection](../programming_guide/function#change-detection) describes what CocoIndex tracks.## Where it fits-CocoIndex fits a problem that has these properties:+CocoIndex fits best when a problem has these properties:-- The output is derived. You can compute it again from the source.+- The target is derived. You can compute it again from the source.- The source changes through edits and deletes, as well as through new items.- Each item costs time or money to process: an embedding, an LLM call, OCR, or a parser.-- Readers need current output, or you change the transformation often.+- Your application needs a current target, or you change the transformation often.[CocoIndex vs other compute frameworks](https://cocoindex.io/comparison/) shows how it relates to data processing engines, orchestrators and other tools.## How it runs- **CocoIndex is an open-source library.** <Lang only="python">`pip install cocoindex` adds it to your project.</Lang><Lang only="rust">The `cocoindex` crate builds into your own binary, with no Python runtime.</Lang> Your code and the engine run in your own process. The license is Apache-2.0.-- **You operate no server for it.** CocoIndex keeps its record of previous runs in an embedded database, at a [local path](../programming_guide/app#database-path) that you set. Keep that path on storage that persists.+- **You operate no server for it.** CocoIndex keeps its record of earlier runs in an embedded database, at a [local path](../programming_guide/app#database-path) that you set. Keep that path on storage that persists.- **You choose when it runs.** A run processes the changes and exits, so a scheduler can start it. In live mode, the app stays running.-- **It has no hosted service.** CocoIndex reads your sources and writes your targets from your own process. The library sends [anonymous usage events](../about/telemetry) with no data from your pipeline, and you can turn them off.+- **It has no hosted service.** CocoIndex reads your sources and writes your targets from your own process.<Lang only="python"> The library sends [anonymous usage events](../about/telemetry) with no data from your pipeline, and you can turn them off.</Lang>The embedded state is on one machine.For team deployments with shared state in Postgres, see [CocoIndex Plus](https://cocoindex.io/enterprise/).@@ -351,10 +416,10 @@ For team deployments with shared state in Postgres, see [CocoIndex Plus](https:/## The Rust SDK-The Rust SDK is the `cocoindex` crate. It has the same programming model as the Python SDK and runs on the same engine, with the same state database format:+The Rust SDK is the `cocoindex` crate. It has the same programming model as the Python SDK. It runs on the same engine, with the same state database format:-- An **app** is an async function that receives a `&Ctx` and declares target states through it. `App::open` opens the app, and `app.run(...)` runs one update.-- **Functions** are `async fn`s marked with `#[cocoindex::function]`. `#[cocoindex::function(memo)]` memoizes one, and `#[cocoindex::function(batching)]` batches calls to it.+- An **app** is an async function that receives a `Ctx` and declares target states through it. `App::open` opens the app, and `app.run(...)` runs one update.+- **Functions** are `async fn` items marked with `#[cocoindex::function]`. `#[cocoindex::function(memo)]` memoizes one, and `#[cocoindex::function(batching)]` batches calls to it.- **Processing components** are mounted with `mount!`, `use_mount!` and `mount_each!`, at stable component paths.- **Resources**, such as a database connection or a model, are shared through typed context keys (`cocoindex::context_key!`) and read with `ctx.get_key(&KEY)`.- **Connectors and operations** are Cargo features, so a crate builds only what it uses.diff --git a/docs/src/content/docs/getting_started/quickstart.mdx b/docs/src/content/docs/getting_started/quickstart.mdxindex 6fa83a13..94900f92 100644--- a/docs/src/content/docs/getting_started/quickstart.mdx+++ b/docs/src/content/docs/getting_started/quickstart.mdx@@ -5,6 +5,7 @@ description: >and watch incremental processing only reprocess files that actually changed.languages: [python]---+import Formula from '/src/components/Formula.astro';import AppExample from '/src/components/diagrams/concepts/AppExample.astro';import FileProcess from '/src/components/diagrams/concepts/FileProcess.astro';import ComponentsFanout from '/src/components/diagrams/concepts/ComponentsFanout.astro';@@ -26,8 +27,12 @@ Build an app that converts PDF files to Markdown and saves them to a local direcYou write the transformation as ordinary Python functions. You write no code for updates or deletes.+<Formula>+**Target = F(Source)**+</Formula>+When a PDF changes, CocoIndex converts it again and updates its Markdown output.When you change the code of the transformation, CocoIndex does the same for every PDF.[Why CocoIndex](./overview) describes the problem that this solves.diff --git a/docs/src/content/docs/programming_guide/core_concepts.mdx b/docs/src/content/docs/programming_guide/core_concepts.mdxindex 21cbdb31..63a7895c 100644--- a/docs/src/content/docs/programming_guide/core_concepts.mdx+++ b/docs/src/content/docs/programming_guide/core_concepts.mdx@@ -3,6 +3,7 @@ title: CocoIndex *core concepts*description: >Declare your outputs. CocoIndex applies changes and reuses cached results.---+import Formula from '/src/components/Formula.astro';import Tabs from '../../../components/Tabs.astro';import PipelinePlayground from '../../../components/PipelinePlayground.astro';@@ -23,8 +24,12 @@ It updates only the affected part of the target, such as a search database.Declare the target state you want from the current source data.CocoIndex computes and applies the changes needed to match it.+<Formula>+**Target = F(Source)**+</Formula>+`F` is your transformation code.The target state is a pure function of the source state, with no other side effects.Transformations read sources and produce target data, such as database rows or files.diff --git a/docs/src/content/example-posts/multi-codebase-summarization.md b/docs/src/content/example-posts/multi-codebase-summarization.mdindex 5301fba3..40edae48 100644--- a/docs/src/content/example-posts/multi-codebase-summarization.md+++ b/docs/src/content/example-posts/multi-codebase-summarization.md@@ -28,7 +28,7 @@ This example uses structured LLM outputs to analyze code and generate documentatYou declare the transformation logic with native Python without worrying about changes.Think:-**target_state = transformation(source_state)**+**Target = F(Source)**When your source data is updated, or your processing logic is changed (for example, switching to a different model, updating your LLM extraction logic), CocoIndex reprocesses affected files and updates their wiki pages.diff --git a/docs/src/data/docs-meta.json b/docs/src/data/docs-meta.jsonindex 50b60c56..b7f7724d 100644--- a/docs/src/data/docs-meta.json+++ b/docs/src/data/docs-meta.json@@ -1,5 +1,5 @@{- "_version": "1.0.14",+ "_version": "1.3.1","files": {"advanced_topics": {"reviewedTs": 1793793600@@ -222,7 +222,7 @@"reviewedTs": 1793793600},"getting_started/overview": {- "reviewedTs": 1793793600+ "reviewedTs": 1796472000},"getting_started/quickstart": {"reviewedTs": 1793793600