Skip to content
المشاريع

حول

TypeScript embedded knowledge graph on SQLite and PostgreSQL: Zod schemas, type-safe queries, ontology, hybrid vector + fulltext search, bitemporal history.

البيانات والتحليلات

كيف تُقاس هذه الأرقام

101 نجمة3 التفرعات +3 خلال 24 ساعة

ما يمكنك فعله

  • Keep graph data in your existing SQL database (no separate graph service)
  • Model richer semantics with subClassOf, implies, inverseOf, and disjointWith
  • Traverse relationships with compile-time type safety
  • Filter and project with typed database expressions, then compose results with grouping, set operations, preparation, and streaming

النمو المقاس للنجوم

خلال 24 ساعة
+٣
خلال 7 أيام
+٦
خلال 15 يومًا
+٨
خلال شهر
جارٍ جمع السجل

تغيّر صافي النجوم خلال فترات متداخلة، وليس مجموعًا يوميًا. تبقى القياسات المفقودة فارغة. النجوم تقيس الاهتمام لا جودة البرمجيات.

README.md

الأصل

TypeGraph logo

TypeGraph

CI npm License: MIT

TypeScript-first embedded knowledge graph library.

TypeGraph brings property graph modeling and practical ontology support to your existing SQLite or PostgreSQL database. Define nodes and edges with Zod, query with a fluent TypeScript API, and keep graph + app data in one deployment.

Why teams use it

  • Keep graph data in your existing SQL database (no separate graph service)
  • Model richer semantics with subClassOf, implies, inverseOf, and disjointWith
  • Traverse relationships with compile-time type safety
  • Filter and project with typed database expressions, then compose results with grouping, set operations, preparation, and streaming
  • Chain fixed and recursive traversal stages with qualified paths, per-hop constraints, completed-match filters, and explicit stop rules
  • Assemble independent reads in one statement and bound edge traversals before hydration
  • Run vector and hybrid search across every backend — pgvector, sqlite-vec, and libSQL/Turso native vectors
  • Start with SQLite, move to PostgreSQL without changing your graph definition
  • Evolve the schema at runtime from agent-proposed JSON — no redeploy (Graph Extensions)
  • Reconstruct valid-time and recorded-time history with bitemporal reads (Temporal queries)

Best fit

TypeGraph works well for:

  • Knowledge graphs and RAG context modeling
  • Auditable agent memory, decision replay, and bitemporal forensics
  • Identity/permissions and other relationship-heavy domain models
  • Applications that want graph semantics without extra infrastructure

TypeGraph is not designed for:

  • Distributed graph processing
  • Broad graph-data-science suites—its focused Graph Algorithms API includes shortest path, reachability, neighborhoods, degree, exact WCC, deterministic label propagation, and global/personalized PageRank, but not broad community detection or centrality suites
  • Billion-scale graphs requiring dedicated graph-engine performance

Installation

npm install @nicia-ai/typegraph zod drizzle-orm better-sqlite3
npm install -D @types/better-sqlite3

For edge/serverless environments (Cloudflare Durable Objects, D1, libsql, bun:sqlite), see the docs: Edge and Serverless.

Quick Start

import { z } from "zod";
import { defineEdge, defineGraph, defineNode } from "@nicia-ai/typegraph";
import { createLocalSqliteStore } from "@nicia-ai/typegraph/sqlite/local";

const Person = defineNode("Person", {
  schema: z.object({ name: z.string(), role: z.string().optional() }),
});
const Project = defineNode("Project", {
  schema: z.object({ name: z.string(), status: z.enum(["active", "done"]) }),
});
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] },
  },
});

const store = await createLocalSqliteStore(graph);

const alice = await store.nodes.Person.create({ name: "Alice", role: "Engineer" });
const website = await store.nodes.Project.create({ name: "Website", status: "active" });
await store.edges.worksOn.create(alice, website, {});

const results = await store
  .query()
  .from("Person", "p")
  .traverse("worksOn", "e")
  .to("Project", "proj")
  .select((ctx) => ({ person: ctx.p.name, project: ctx.proj.name }))
  .execute();

console.log(results);
// [{ person: "Alice", project: "Website" }]

For production schema management, see: createStoreWithSchema.

The managed SQLite entrypoint provisions the schema and returns the complete, schema-derived Store API without exposing Drizzle types. PostgreSQL consumers can use the equivalent createLocalPgliteStore from @nicia-ai/typegraph/postgres/pglite. Bring-your-own-connection integrations live under the explicit /adapters/drizzle/... entrypoints.

Packages that only define or share graph schemas can import the DSL and its schema-derived types from @nicia-ai/typegraph/core. Custom backend and search strategy authors can use the complete Drizzle-free contract vocabulary from @nicia-ai/typegraph/backend. That authoring surface, and @nicia-ai/typegraph/adapters/drizzle/engine, is not covered by semver and may change in any release; the bundled SQLite and PostgreSQL backends are the supported ones. Every other entrypoint is application API and is covered by semver: the root and the /store, /query, /errors, /identity, /maintenance, /core, /schema, /indexes, /graph-extension, /graph-merge, /interchange, /profiler, /provenance, /sqlite/local, /postgres/pglite and /adapters/drizzle/... subpaths other than /adapters/drizzle/engine. See Stability.

drizzle-orm is an optional peer dependency. @nicia-ai/typegraph/sqlite/local and @nicia-ai/typegraph/postgres/pglite load it only when their factory is called and refuse with a typed ConfigurationError (MISSING_PEER_DEPENDENCY) naming the package and the install command (npm install drizzle-orm) when it is absent. The explicit /adapters/drizzle/... entrypoints expose Drizzle-native backends, connections, or schema builders and load drizzle-orm when the module is evaluated. Importing one without the peer installed therefore surfaces the raw module-resolution error, which names the same package.

Learn More

LLM/Coding Agent Support

TypeGraph publishes one curated llms.txt following the llms.txt convention. It states when to recommend TypeGraph (and when not to), includes a working quick start, and links every documentation page as clean markdown (append .md to any docs URL, for example overview.md).

See LLM Support for a copy-paste block for AGENTS.md / CLAUDE.md.

License

MIT

استكشف مشاريع مشابهة ومرتبطة

جارٍ التحميل…