TypeScript SDK Examples
The KalamDB repo currently ships four runnable TypeScript examples. Start with the React one if you want the current app pattern.
They live in the repository under:
examples/react-ai-chatexamples/simple-typescriptexamples/chat-with-aiexamples/summarizer-agent
Each runnable example has its own setup path and its own test.
1. React AI Chat
Repository path: examples/react-ai-chat
What it demonstrates:
@kalamdb/reactwithKalamProviderandLiveQueries- one React screen reading conversations, messages, and typing tokens together
- file attachments, streamed typing tokens, final assistant inserts, and approval actions
- browser demo mode and the server-backed topic-agent path
Simple multi-table component:
Why it matters:
This is the current React app pattern in the repo. One provider owns the client, one LiveQueries block owns the live datasets, and the UI renders rows directly instead of syncing copies into local state.
Run it:
Test it:
npm run setup imports chat-app.sql, clears existing example topics, seeds the default conversation, and writes .env.local. For browser-only demo mode, skip setup and set VITE_KALAMDB_DEMO_MODE=true.
2. Realtime Ops Feed
Repository path: examples/simple-typescript
What it demonstrates:
live()for live browser updatesquery()for writes from the browser- browser auth with
Auth.basic(...) - cross-tab realtime sync from one write
Why it matters:
This is the smallest browser example that still feels real. It avoids wrapper layers, keeps the full flow inside one React component, and shows the recommended pattern: one live query returns the current rows while USER-table isolation keeps each signed-in user inside their own data partition.
Run it:
Test it:
The Playwright test opens two tabs, inserts one row, and verifies both tabs update.
3. Chat With AI
Repository path: examples/chat-with-ai
What it demonstrates:
- generated ORM tables in both the browser and the worker
- topic fan-out from
ALTER TOPIC ... ADD SOURCE ... runConsumer<T>()with a generated row typekalamDriver(client)andexecuteAsUser(...)for typed writes in the worker
Simple worker snippet:
Why it matters:
This example shows the full table → topic → worker → browser loop with the current typed SDK path. The browser writes with generated tables, the worker consumes generated row types, and the reply insert stays typed as well.
Run it:
Test it:
The Playwright test starts the agent, opens two tabs, sends a message, and waits for the assistant reply in both tabs.
4. Summarizer Agent
Repository path: examples/summarizer-agent
What it demonstrates:
- a worker-only
runConsumer()example - row enrichment back into the source table
- a failure sink table for exhausted retries
Why it matters:
If you do not need a browser at all, this is the cleanest place to start. It shows how little code is required to build a useful background worker around KalamDB topics.
Run it:
Test it:
The integration test inserts a row and waits until the worker writes the summary back.
5. Vector Search Pattern
Repository reference: backend/tests/scenarios/scenario_14_vector_rag.rs
What it demonstrates:
EMBEDDING(n)columns for document and attachment vectorsALTER TABLE ... CREATE INDEX ... USING COSINE- nearest-neighbor SQL with
ORDER BY COSINE_DISTANCE(...) LIMIT k - joining vector hits back to FILE-backed document rows
Why it matters:
This is the current KalamDB pattern for semantic retrieval and RAG. You keep rich document rows in one table, keep embeddings in a keyed companion table, and run vector search with normal SQL. The same flow works with TYPE = 'USER', so each signed-in user only searches their own embeddings.
TypeScript query example:
SQL setup example:
Read next: