The Knowledge Graph for TypeScript
Define your ontology with Zod. Query with a fluent builder. Extend it at runtime when your agents need more.
Define. Connect. Query. Evolve.
Your schema is your database. Your types are your queries.
import { defineNode, defineEdge, defineGraph, createStore } from "@nicia-ai/typegraph";
import { z } from "zod";
// 1. Define your ontology
const Person = defineNode("Person", {
schema: z.object({ name: z.string(), role: z.string() })
});
const Project = defineNode("Project", {
schema: z.object({ name: z.string(), status: z.string() })
});
const worksOn = defineEdge("worksOn");
const graph = defineGraph({
id: "my_app",
nodes: { Person: { type: Person }, Project: { type: Project } },
edges: { worksOn: { type: worksOn, from: [Person], to: [Project] } }
});
// 2. Query with full type safety
const results = await store.query()
.from("Person", "p")
.whereNode("p", p => p.role.eq("Engineer"))
.traverse("worksOn", "e")
.to("Project", "proj")
.select(ctx => ({ person: ctx.p.name, project: ctx.proj.name }))
.execute(); import { defineNode, searchable, embedding } from "@nicia-ai/typegraph";
import { z } from "zod";
// 1. Declare semantic + fulltext fields right in the Zod schema
const Document = defineNode("Document", {
schema: z.object({
title: searchable({ language: "english" }),
body: searchable({ language: "english" }),
embedding: embedding(1536),
})
});
// 2. Hybrid retrieval: BM25 fulltext + vector similarity, fused with RRF
const hits = await store.search.hybrid("Document", {
limit: 10,
vector: { fieldPath: "embedding", queryEmbedding: await embed(q) },
fulltext: { query: q },
});
// 3. Or compose fulltext into any graph traversal — authorised search,
// multi-tenant filters, anything you can already express in a query.
const scoped = await store.query()
.from("User", "u").whereNode("u", u => u.id.eq(currentUserId))
.traverse("canRead", "e").to("Document", "d")
.whereNode("d", d => d.$fulltext.matches(query, 10))
.select(ctx => ctx.d).execute(); import { defineGraphExtension } from "@nicia-ai/typegraph";
// 1. An agent proposes a typed kind from observed data.
const proposal = defineGraphExtension({
nodes: {
Paper: {
description: "An academic paper inferred from the corpus",
properties: {
title: { type: "string", minLength: 1 },
doi: { type: "string", minLength: 1 },
year: { type: "number", int: true, min: 1900, max: 2100 },
},
unique: [{ name: "paper_doi_unique", fields: ["doi"] }],
},
},
});
// 2. Operator approves; commit atomically as a new schema version.
const evolved = await store.evolve(proposal);
// 3. Read and write the new kind dynamically — no codegen, no redeploy.
const papers = evolved.getNodeCollection("Paper")!;
await papers.create({
title: "Attention Is All You Need",
doi: "10.5555/3295222.3295349",
year: 2017,
}); Why TypeGraph?
Build smarter applications with a database that understands your domain.
Universal Schema
Define your data model once with Zod. TypeGraph orchestrates your database, API validation, and TypeScript types automatically. No more syncing separate layers.
AI-Native Structure
Built for RAG and agentic systems. Hybrid retrieval blends BM25 fulltext with vector similarity in a single query, and your ontology gives LLMs the structured context they need.
Runtime Schema Evolution
Let agents propose new kinds and edges. store.evolve() commits reviewed extensions as durable schema versions — no codegen,
no redeploy.
Smart Relationships
Go beyond foreign keys. Model real-world logic with implies, inverseOf, and transitive rules that the database understands and enforces.
Zero-Infrastructure Start
Prototyping? Start with an in-memory or SQLite graph. Scaling? Swap the adapter to PostgreSQL without changing a line of your application logic.
Type-Safe Query Builder
Forget strict SQL strings. Build complex, multi-hop graph traversals with a fluent TypeScript API that catches errors before you run code.
What can you build?
TypeGraph excels where relationships matter most.
Knowledge Graphs for RAG
Feed your LLMs high-fidelity, structured context. Map documents to concepts, authors, and entities — then retrieve with hybrid search (vector + fulltext) and let agents extend the ontology when they encounter new types.
Build this →Complex Identity & Access
Model fine-grained permissions (ReBAC) with ease. Traverse organizational hierarchies and group memberships in a single, type-safe query.
Build this →Recommendation Engines
Discover hidden connections. "Users who bought X also bought Y" becomes a trivial graph traversal rather than a complex series of SQL JOINs.
Build this →Stay in the loop
Occasional updates on new features, guides, and releases. No spam.