{"_id":"@ashes_born/graph-rag-ts","_rev":"6-4a088fae6d97b035690cc33c6be098d6","name":"@ashes_born/graph-rag-ts","dist-tags":{"latest":"0.1.7"},"versions":{"0.1.1":{"name":"@ashes_born/graph-rag-ts","version":"0.1.1","license":"MIT","_id":"@ashes_born/graph-rag-ts@0.1.1","maintainers":[{"name":"ashes_born","email":"justlikeashes@gmail.com"}],"dist":{"shasum":"9fdd521c4afbce2482028ac86701d737d7e1f48e","tarball":"https://registry.npmjs.org/@ashes_born/graph-rag-ts/-/graph-rag-ts-0.1.1.tgz","fileCount":156,"integrity":"sha512-IXje/6+bE6WeZZG6g+ZYmX78WVwUpKawK4z2t5kS7Ok/7zUtLTLXbKh9dZNC0nKr5F8xHuKf1kmWSRH1WQS0NA==","signatures":[{"sig":"MEUCICCroxg75tJ4o+kY4aL6KN/+uSlL7dX1Lh1c444UZWwfAiEAnYVB3Lbfkp4cX8urkfy9HkTy0TCYnIHVhHQt36Nl0Kg=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":559796},"main":"./src/index.ts","type":"module","prisma":{"schema":"prisma/schema.prisma"},"engines":{"bun":">=1.1.0","node":">=20"},"exports":{".":"./src/index.ts","./model-loader":"./src/build/modelLoader.ts","./prisma-client":"./src/build/helper/prismaClient.ts"},"gitHead":"9d248058e8dcf73eec560f0245295406117c838f","scripts":{"demo":"bun run examples/demo.ts","lint":"eslint .","test":"NODE_ENV=test bun test","db:push":"prisma db push","benchmark":"bun run src/benchmark/run.ts","typecheck":"tsc --noEmit","db:generate":"prisma generate","postinstall":"prisma generate"},"_npmUser":{"name":"ashes_born","email":"justlikeashes@gmail.com"},"_npmVersion":"11.5.1","description":"Reference implementation of a chunked GraphRAG engine: markdown-aware ingestion, Leiden community detection, hybrid vector+keyword retrieval and evidence-grounded answers (Bun + TypeScript).","directories":{},"_nodeVersion":"24.7.0","dependencies":{"pino":"^8.20.0","marked":"^18.0.11","@prisma/client":"6.19.3","@langchain/core":"^1.2.9","@langchain/openai":"^1.5.9","@langchain/deepseek":"^1.1.10","@graphrs/igraph-wasm":"^0.1.4","@langchain/textsplitters":"^1.0.1"},"_hasShrinkwrap":false,"packageManager":"pnpm@10.22.0","devDependencies":{"eslint":"^9.18.0","prisma":"6.19.3","globals":"^15.14.0","@eslint/js":"^9.18.0","@types/bun":"latest","typescript":"^5.8.2","@types/node":"^24.7.0","typescript-eslint":"^8.21.0"},"_npmOperationalInternal":{"tmp":"tmp/graph-rag-ts_0.1.1_1788270462533_0.11096365619870152","host":"s3://npm-registry-packages-npm-production"}},"0.1.3":{"name":"@ashes_born/graph-rag-ts","version":"0.1.3","license":"MIT","_id":"@ashes_born/graph-rag-ts@0.1.3","maintainers":[{"name":"ashes_born","email":"justlikeashes@gmail.com"}],"dist":{"shasum":"20381b4560c497b562780c76646b170139375e41","tarball":"https://registry.npmjs.org/@ashes_born/graph-rag-ts/-/graph-rag-ts-0.1.3.tgz","fileCount":156,"integrity":"sha512-K9QFeRBxR9CJ1AX8kXLowsa4QtbzRubEkhFk1AqmyKh+iPu042MQabL/CV9oA5VfBlQxqfUa8XuUQm5NG0PMlw==","signatures":[{"sig":"MEYCIQCw7rr8cBM2Ez7WxIueTpQJOAdJDwKOqtng2+R/j5Y1EAIhAL/jVBQ+1FTnYmFZvO9CFSg1/tRd56YdPB9zoB3/zEgq","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":561327},"main":"./src/index.ts","type":"module","prisma":{"schema":"prisma/schema.prisma"},"engines":{"bun":">=1.1.0","node":">=20"},"exports":{".":"./src/index.ts","./*":"./src/*.ts","./build/*":"./src/build/*.ts","./input/*":"./src/input/*.ts","./helper/*":"./src/helper/*.ts","./namespace/*":"./src/namespace/*.ts","./retrieval/*":"./src/retrieval/*.ts","./model-loader":"./src/build/modelLoader.ts","./prisma-client":"./src/build/helper/prismaClient.ts"},"gitHead":"408acba01fb96e36a384f0883165851f1d98033c","scripts":{"demo":"bun run examples/demo.ts","lint":"eslint .","test":"NODE_ENV=test bun test","db:push":"prisma db push","benchmark":"bun run src/benchmark/run.ts","typecheck":"tsc --noEmit","db:generate":"prisma generate","postinstall":"prisma generate"},"_npmUser":{"name":"ashes_born","email":"justlikeashes@gmail.com"},"_npmVersion":"11.5.1","description":"Reference implementation of a chunked GraphRAG engine: markdown-aware ingestion, Leiden community detection, hybrid vector+keyword retrieval and evidence-grounded answers (Bun + TypeScript).","directories":{},"_nodeVersion":"24.7.0","dependencies":{"pino":"^8.20.0","marked":"^18.0.11","@prisma/client":"6.19.3","@langchain/core":"^1.2.9","@langchain/openai":"^1.5.9","@langchain/deepseek":"^1.1.10","@graphrs/igraph-wasm":"^0.1.4","@langchain/textsplitters":"^1.0.1"},"_hasShrinkwrap":false,"packageManager":"pnpm@10.22.0","devDependencies":{"eslint":"^9.18.0","prisma":"6.19.3","globals":"^15.14.0","@eslint/js":"^9.18.0","@types/bun":"latest","typescript":"^5.8.2","@types/node":"^24.7.0","typescript-eslint":"^8.21.0"},"_npmOperationalInternal":{"tmp":"tmp/graph-rag-ts_0.1.3_1788280581927_0.6955879899818445","host":"s3://npm-registry-packages-npm-production"}},"0.1.4":{"name":"@ashes_born/graph-rag-ts","version":"0.1.4","license":"MIT","_id":"@ashes_born/graph-rag-ts@0.1.4","maintainers":[{"name":"ashes_born","email":"justlikeashes@gmail.com"}],"dist":{"shasum":"ce8aeee79d78ebeb91035b5a1f26e1078e3e8528","tarball":"https://registry.npmjs.org/@ashes_born/graph-rag-ts/-/graph-rag-ts-0.1.4.tgz","fileCount":148,"integrity":"sha512-iwZYCZKHROa/eDfGQ80eDwRKFZzLGcxXS+aDlorVAUgXh30K8wXV8+tkNFRAQR19PNsiHWbO4J84VJPCBwHG4w==","signatures":[{"sig":"MEUCIQCnGIoDLrb1vDryxmEHq7qgPhI7+hMRIM/6l0WgXL8+pwIgDm6mql/CxQazF+4t+RVrO6lPgja0Tc51x0w+oRGc5I8=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":389812},"main":"./src/index.ts","type":"module","prisma":{"schema":"prisma/schema.prisma"},"engines":{"bun":">=1.1.0","node":">=20"},"exports":{".":"./src/index.ts","./*":"./src/*.ts","./build/*":["./src/build/*.ts","./src/build/*/index.ts"],"./input/*":["./src/input/*.ts","./src/input/*/index.ts"],"./helper/*":["./src/helper/*.ts","./src/helper/*/index.ts"],"./namespace/*":["./src/namespace/*.ts","./src/namespace/*/index.ts"],"./retrieval/*":["./src/retrieval/*.ts","./src/retrieval/*/index.ts"],"./model-loader":"./src/build/modelLoader.ts","./prisma-client":"./src/build/helper/prismaClient.ts"},"gitHead":"fae82cec5d3a3e83d93fe6e241c7387fd44d21c6","scripts":{"demo":"bun run examples/demo.ts","lint":"eslint .","test":"NODE_ENV=test bun test","db:push":"prisma db push","typecheck":"tsc --noEmit","db:generate":"prisma generate","postinstall":"prisma generate","demo:benchmark":"bun run examples/benchmark-recall-demo.ts"},"_npmUser":{"name":"ashes_born","email":"justlikeashes@gmail.com"},"_npmVersion":"11.5.1","description":"Reference implementation of a chunked GraphRAG engine: markdown-aware ingestion, Leiden community detection, hybrid vector+keyword retrieval and evidence-grounded answers (Bun + TypeScript).","directories":{},"_nodeVersion":"24.7.0","dependencies":{"pino":"^8.20.0","marked":"^18.0.11","@prisma/client":"6.19.3","@langchain/core":"^1.2.9","@langchain/openai":"^1.5.9","@langchain/deepseek":"^1.1.10","@graphrs/igraph-wasm":"^0.1.4","@langchain/textsplitters":"^1.0.1"},"_hasShrinkwrap":false,"packageManager":"pnpm@10.22.0","devDependencies":{"eslint":"^9.18.0","prisma":"6.19.3","globals":"^15.14.0","@eslint/js":"^9.18.0","@types/bun":"latest","typescript":"^5.8.2","@types/node":"^24.7.0","typescript-eslint":"^8.21.0"},"_npmOperationalInternal":{"tmp":"tmp/graph-rag-ts_0.1.4_1788362959569_0.5760936832358698","host":"s3://npm-registry-packages-npm-production"}},"0.1.5":{"name":"@ashes_born/graph-rag-ts","version":"0.1.5","license":"MIT","_id":"@ashes_born/graph-rag-ts@0.1.5","maintainers":[{"name":"ashes_born","email":"justlikeashes@gmail.com"}],"dist":{"shasum":"f30cc2cb91a936603a9a0f157ed0f5d2f2e7ab99","tarball":"https://registry.npmjs.org/@ashes_born/graph-rag-ts/-/graph-rag-ts-0.1.5.tgz","fileCount":148,"integrity":"sha512-2YKYfLPDOFbjW10KYaM8DP8w1MXnrGQWZFRSil9YJxxk0BmkMqMVUmE6oj3s8J+QYa5qV6aeGfxasfPXf2mpIg==","signatures":[{"sig":"MEYCIQDpBvIef8aF3gB55CLDW8nFoWJglVJddQftMJjnBkmN0wIhAM47f3a840xnlbBbifmqzwUTVoLWKrHNWzVVsM9BkRkl","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":383770},"main":"./src/index.ts","type":"module","prisma":{"schema":"prisma/schema.prisma"},"engines":{"bun":">=1.1.0","node":">=20"},"exports":{".":"./src/index.ts","./*":"./src/*.ts","./build/*":["./src/build/*.ts","./src/build/*/index.ts"],"./input/*":["./src/input/*.ts","./src/input/*/index.ts"],"./helper/*":["./src/helper/*.ts","./src/helper/*/index.ts"],"./namespace/*":["./src/namespace/*.ts","./src/namespace/*/index.ts"],"./retrieval/*":["./src/retrieval/*.ts","./src/retrieval/*/index.ts"],"./model-loader":"./src/build/modelLoader.ts","./prisma-client":"./src/build/helper/prismaClient.ts"},"gitHead":"a7afa2062b6b3545acec5bd45df0b99f0384b95c","scripts":{"demo":"bun run examples/demo.ts","lint":"eslint .","test":"NODE_ENV=test bun test","db:push":"prisma db push","typecheck":"tsc --noEmit","db:generate":"prisma generate","postinstall":"prisma generate","demo:benchmark":"bun run examples/benchmark-recall-demo.ts"},"_npmUser":{"name":"ashes_born","email":"justlikeashes@gmail.com"},"_npmVersion":"11.5.1","description":"Reference implementation of a chunked GraphRAG engine: markdown-aware ingestion, Leiden community detection, hybrid vector+keyword retrieval and evidence-grounded answers (Bun + TypeScript).","directories":{},"_nodeVersion":"24.7.0","dependencies":{"pino":"^8.20.0","marked":"^18.0.11","@prisma/client":"6.19.3","@langchain/core":"^1.2.9","@langchain/openai":"^1.5.9","@langchain/deepseek":"^1.1.10","@graphrs/igraph-wasm":"^0.1.4","@langchain/textsplitters":"^1.0.1"},"_hasShrinkwrap":false,"packageManager":"pnpm@10.22.0","devDependencies":{"eslint":"^9.18.0","prisma":"6.19.3","globals":"^15.14.0","@eslint/js":"^9.18.0","@types/bun":"latest","typescript":"^5.8.2","@types/node":"^24.7.0","typescript-eslint":"^8.21.0"},"_npmOperationalInternal":{"tmp":"tmp/graph-rag-ts_0.1.5_1788366671602_0.862009168322637","host":"s3://npm-registry-packages-npm-production"}},"0.1.6":{"name":"@ashes_born/graph-rag-ts","version":"0.1.6","license":"MIT","_id":"@ashes_born/graph-rag-ts@0.1.6","maintainers":[{"name":"ashes_born","email":"justlikeashes@gmail.com"}],"dist":{"shasum":"b7c6e87341ed99788401b6262a569281a29a344e","tarball":"https://registry.npmjs.org/@ashes_born/graph-rag-ts/-/graph-rag-ts-0.1.6.tgz","fileCount":156,"integrity":"sha512-wIuV7YUOPzj4vKdw7oLxlhMaMd0rUZAIkvDcLdcM+VhfMQMFR6dAcHnTriF5W6jklbch3DL7J5LsBqkNA6N85Q==","signatures":[{"sig":"MEUCIEKKPI+HhLw96ZdZKmzTZZmHN6YjH5OYv3nFpQihGrgrAiEApcHOc1BxTqjgt7Rp4pXnjWQoeoWrYxR+wGPfQUOIgq8=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":403907},"main":"./src/index.ts","type":"module","prisma":{"schema":"prisma/schema.prisma"},"engines":{"bun":">=1.1.0","node":">=20"},"exports":{".":"./src/index.ts","./*":"./src/*.ts","./adapter":"./src/build/adapter/index.ts","./build/*":["./src/build/*.ts","./src/build/*/index.ts"],"./input/*":["./src/input/*.ts","./src/input/*/index.ts"],"./helper/*":["./src/helper/*.ts","./src/helper/*/index.ts"],"./namespace/*":["./src/namespace/*.ts","./src/namespace/*/index.ts"],"./retrieval/*":["./src/retrieval/*.ts","./src/retrieval/*/index.ts"],"./model-loader":"./src/build/modelLoader.ts","./prisma-client":"./src/build/helper/prismaClient.ts"},"gitHead":"004653c1cffb927f32c2561f173b9c2a6d614e79","scripts":{"demo":"bun run examples/demo.ts","lint":"eslint .","test":"NODE_ENV=test bun test","db:push":"prisma db push","typecheck":"tsc --noEmit","db:generate":"prisma generate","postinstall":"prisma generate","version:bump":"bun run scripts/bump-version.ts","demo:benchmark":"bun run examples/benchmark-recall-demo.ts"},"_npmUser":{"name":"ashes_born","email":"justlikeashes@gmail.com"},"_npmVersion":"11.5.1","description":"Reference implementation of a chunked GraphRAG engine: markdown-aware ingestion, Leiden community detection, hybrid vector+keyword retrieval and evidence-grounded answers (Bun + TypeScript).","directories":{},"_nodeVersion":"24.7.0","dependencies":{"pino":"^8.20.0","marked":"^18.0.11","@prisma/client":"6.19.3","@langchain/core":"^1.2.9","@langchain/openai":"^1.5.9","@langchain/deepseek":"^1.1.10","@graphrs/igraph-wasm":"^0.1.4","@langchain/textsplitters":"^1.0.1"},"_hasShrinkwrap":false,"packageManager":"pnpm@10.22.0","devDependencies":{"eslint":"^9.18.0","prisma":"6.19.3","globals":"^15.14.0","@eslint/js":"^9.18.0","@types/bun":"latest","typescript":"^5.8.2","@types/node":"^24.7.0","typescript-eslint":"^8.21.0"},"_npmOperationalInternal":{"tmp":"tmp/graph-rag-ts_0.1.6_1788680858480_0.3215889449688851","host":"s3://npm-registry-packages-npm-production"}},"0.1.7":{"_id":"@ashes_born/graph-rag-ts@0.1.7","dist":{"shasum":"528055a7a6ba9657a6ca8c7d9fb10da8e85be98c","tarball":"https://registry.npmjs.org/@ashes_born/graph-rag-ts/-/graph-rag-ts-0.1.7.tgz","fileCount":168,"integrity":"sha512-ztqc1sLlVAKhGB9UijS//8GPrOfhv6dyprWD2c36K7iKeBiZFbwqxCfKSNvRkl6ZKjlcKrsinTXCYrsY1BUPAA==","signatures":[{"sig":"MEYCIQCjgJnL1mMgiraWDsdX4wiXP86GsAmNFcK/LSFHauvfBQIhAODbTB5e2RL3fa3PqT7LZ+ZhzoCmEOzAMkfBM/f5d7d6","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDSQcfw1hpuy9RgmcAtG7XKe0Jv9lwP0ZTjanqcQPzGjwIhAPIfzp2yELUaibrz6IpC4CiwC3EKLCSdjorNEPepzkkt"}],"unpackedSize":463600},"main":"./src/index.ts","name":"@ashes_born/graph-rag-ts","type":"module","prisma":{"schema":"prisma/schema.prisma"},"engines":{"bun":">=1.1.0","node":">=20"},"exports":{".":"./src/index.ts","./*":"./src/*.ts","./adapter":"./src/build/adapter/index.ts","./build/*":["./src/build/*.ts","./src/build/*/index.ts"],"./input/*":["./src/input/*.ts","./src/input/*/index.ts"],"./helper/*":["./src/helper/*.ts","./src/helper/*/index.ts"],"./incremental":"./src/build/incremental/index.ts","./namespace/*":["./src/namespace/*.ts","./src/namespace/*/index.ts"],"./retrieval/*":["./src/retrieval/*.ts","./src/retrieval/*/index.ts"],"./model-loader":"./src/build/modelLoader.ts","./prisma-client":"./src/build/helper/prismaClient.ts"},"gitHead":"a170301b55c1afd9bc76e21f77564ccd8b0d89d6","license":"MIT","scripts":{"demo":"bun run examples/demo.ts","lint":"eslint .","test":"NODE_ENV=test bun test","db:push":"prisma db push","typecheck":"tsc --noEmit","db:generate":"prisma generate","postinstall":"prisma generate","version:bump":"bun run scripts/bump-version.ts","demo:benchmark":"bun run examples/benchmark-recall-demo.ts"},"version":"0.1.7","_npmUser":{"name":"ashes_born","email":"justlikeashes@gmail.com"},"_npmVersion":"11.5.1","description":"Reference implementation of a chunked GraphRAG engine: markdown-aware ingestion, Leiden community detection, hybrid vector+keyword retrieval and evidence-grounded answers (Bun + TypeScript).","directories":{},"maintainers":[{"name":"ashes_born","email":"justlikeashes@gmail.com"}],"_nodeVersion":"24.7.0","dependencies":{"pino":"^8.20.0","marked":"^18.0.11","@prisma/client":"6.19.3","@langchain/core":"^1.2.9","@langchain/openai":"^1.5.9","@langchain/deepseek":"^1.1.10","@graphrs/igraph-wasm":"^0.1.4","@langchain/textsplitters":"^1.0.1"},"_hasShrinkwrap":false,"packageManager":"pnpm@10.22.0","devDependencies":{"eslint":"^9.18.0","prisma":"6.19.3","globals":"^15.14.0","@eslint/js":"^9.18.0","@types/bun":"latest","typescript":"^5.8.2","@types/node":"^24.7.0","typescript-eslint":"^8.21.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/graph-rag-ts_0.1.7_1790056295467_0.46595758895653505"}}},"time":{"created":"2026-09-01T13:47:42.390Z","modified":"2026-09-22T05:51:36.410Z","0.1.1":"2026-09-01T13:47:42.666Z","0.1.3":"2026-09-01T16:36:22.071Z","0.1.4":"2026-09-02T15:29:19.711Z","0.1.5":"2026-09-02T16:31:11.747Z","0.1.6":"2026-09-06T07:47:38.613Z","0.1.7":"2026-09-22T05:51:35.558Z"},"license":"MIT","description":"Reference implementation of a chunked GraphRAG engine: markdown-aware ingestion, Leiden community detection, hybrid vector+keyword retrieval and evidence-grounded answers (Bun + TypeScript).","maintainers":[{"name":"ashes_born","email":"justlikeashes@gmail.com"}],"readme":"# graphrag-ts\n\n> TypeScript GraphRAG for Markdown corpora. Build a knowledge graph, detect communities, and answer with evidence-backed retrieval.\n\n## Why this project exists\n\nTraditional vector RAG is good at similarity search, but it is limited when you need cross-document structure, entity relationships, and global context. This repository implements a GraphRAG-style pipeline in TypeScript so you can index Markdown content and retrieve answers from a graph-backed knowledge base without a Python runtime or a custom product framework.\n\nThe project is designed for practical backend use:\n\n- ingest Markdown files and split them into chunks\n- extract entities, edges, and claims\n- store graph data in PostgreSQL via Prisma\n- detect communities and build community summaries\n- support incremental ingestion with SHA-256 diffing and cascade document pruning\n- differential community summary updates (0 LLM cost for unchanged communities)\n- fuse vector, keyword, and topology-based recall for retrieval\n- generate answers from evidence instead of raw model output alone\n\n## What it gives you\n\n- a readable GraphRAG reference implementation in TypeScript\n- database-backed persistence for entities, claims, edges, and communities\n- full and incremental builds (`buildIncrementalRAG` / `startIncrementalBuild` / `deleteRAGDocument`)\n- namespace-aware builds for multi-tenant or multi-corpus usage\n- hybrid retrieval that combines semantic, keyword, and graph signals\n- deterministic fallback behavior when model-based chunking fails\n- a small public API that is easy to embed in an application service\n\n## Core pipeline\n\n```mermaid\nflowchart LR\n    MD[Markdown files] --> SPLIT[Chunking and slicing]\n    SPLIT --> GRAPH[Entity + edge + claim graph]\n    GRAPH --> COMM[Community detection]\n    COMM --> SUMMARY[Community summaries]\n    Q[User query] --> INTENT[Intent parsing]\n    INTENT --> HYBRID[Hybrid recall: vector + keyword + community]\n    HYBRID --> EVIDENCE[Evidence aggregation]\n    EVIDENCE --> ANSWER[Grounded answer]\n```\n\nThe implementation matches this flow in the codebase:\n\n- `src/build/` handles slicing, graph construction, and community detection\n- `src/retrieval/` handles query parsing, ranking, evidence selection, and answer generation\n- `prisma/schema.prisma` defines the persisted GraphRAG tables\n- `src/index.ts` exposes the main runtime injection and public API\n\n## Quick start\n\n```bash\n# install dependencies\npnpm install\n\n# generate Prisma client\npnpm run db:generate\n\n# copy environment variables\ncp .env.example .env\n\n# apply the schema\npnpm run db:push\n\n# run tests\nbun test\n\n# run the demo\nbun run examples/demo.ts\n```\n\n## Requirements\n\nBefore running the project, make sure you have:\n\n- [pnpm](https://pnpm.io/) 10+\n- [Bun](https://bun.sh) 1.1+\n- PostgreSQL with [pgvector](https://github.com/pgvector/pgvector) enabled\n- a chat model for slicing and judging\n- an embedding model compatible with OpenAI-style APIs\n\n## Runtime configuration\n\nThis repo expects configuration to be provided by the caller. The model loader reads environment variables from `src/build/modelLoader.ts`.\n\n```bash\nDATABASE_URL=\"postgresql://user:pass@localhost:5432/graphrag?schema=public\"\n\nRAG_SLICE_API_KEY=\"your-slice-key\"\nRAG_SLICE_MODEL=\"deepseek-chat\"\nRAG_SLICE_BASE_URL=\"https://api.deepseek.com/\"\n\nRAG_JUDGE_API_KEY=\"your-judge-key\"\nRAG_JUDGE_MODEL=\"deepseek-chat\"\nRAG_JUDGE_BASE_URL=\"https://api.deepseek.com/\"\n\nRAG_EMBED_API_KEY=\"your-embedding-key\"\nRAG_EMBED_MODEL=\"local-embedding-model\"\nRAG_EMBED_BASE_URL=\"http://127.0.0.1:1234/v1\"\n```\n\nTypical runtime injection pattern:\n\n```ts\nimport { PrismaClient } from '@prisma/client';\nimport {\n  injectGraphRAG,\n  GraphRAGRetrievalService,\n  startBuild,\n  createBuildRegistry,\n} from '@ashes_born/graph-rag-ts';\n\nawait injectGraphRAG({\n  database: {\n    client: new PrismaClient({ datasourceUrl: process.env.DATABASE_URL }),\n  },\n  models: [\n    {\n      type: 'slice',\n      baseURL: process.env.RAG_SLICE_BASE_URL!,\n      model: process.env.RAG_SLICE_MODEL!,\n      apiKey: process.env.RAG_SLICE_API_KEY!,\n    },\n    {\n      type: 'judge',\n      baseURL: process.env.RAG_JUDGE_BASE_URL!,\n      model: process.env.RAG_JUDGE_MODEL!,\n      apiKey: process.env.RAG_JUDGE_API_KEY!,\n    },\n    {\n      type: 'embedding',\n      baseURL: process.env.RAG_EMBED_BASE_URL!,\n      model: process.env.RAG_EMBED_MODEL!,\n      apiKey: process.env.RAG_EMBED_API_KEY!,\n    },\n  ],\n});\n\nconst registry = createBuildRegistry();\nconst buildId = startBuild(\n  [{ title: 'sample.md', content: 'Alice works with Bob at Acme Corp.' }],\n  registry,\n  'demo-namespace',\n);\n\nconst service = new GraphRAGRetrievalService();\nconst result = await service.retrieve({\n  query: 'Who works with Alice?',\n  topK: 5,\n});\n\nconsole.log(result.answer);\n```\n\n## Public API\n\nThis repo exposes a compact API surface that matches the implementation (available via root package or subpaths like `@ashes_born/graph-rag-ts/incremental`):\n\n### Ingestion & Incremental APIs\n\n- `startBuild(...)` / `startIncrementalBuild(...)`: starts an async full/incremental build job and returns a build ID\n- `buildRAG(...)` / `buildIncrementalRAG(...)`: runs full/incremental pipeline and returns `BuildSummary`\n- `deleteRAGDocument(...)`: cascades deletion of a document, its chunks, graph edges, and claims\n- `diffDocuments(...)` / `computeCommunityFingerprint(...)`: incremental comparison and topological fingerprint utilities\n- `createBuildRegistry()`: tracks build lifecycle state\n- `GraphRAGRetrievalService`: executes hybrid retrieval and evidence-grounded answer generation\n- `injectGraphRAG(...)`: injects Prisma, model config, and optional defaults\n- `registerChatAdapter(provider, adapter)` / `registerEmbeddingAdapter(provider, adapter)`: register custom LangChain models (e.g. Anthropic, Ollama, Google GenAI)\n\n### Custom LangChain Model Adapters\n\nYou can register any LangChain-compatible model via the adapter layer:\n\n```ts\nimport { registerChatAdapter, registerEmbeddingAdapter } from '@ashes_born/graph-rag-ts';\nimport { ChatAnthropic } from '@langchain/anthropic';\nimport { OllamaEmbeddings } from '@langchain/ollama';\n\n// Register custom chat adapter\nregisterChatAdapter('anthropic', ({ config, isSlice }) => {\n  return new ChatAnthropic({\n    anthropicApiKey: config.apiKey,\n    modelName: config.model,\n  });\n});\n\n// Register custom embedding adapter\nregisterEmbeddingAdapter('ollama', ({ config }) => {\n  return new OllamaEmbeddings({\n    baseUrl: config.baseURL,\n    model: config.model,\n  });\n});\n```\n- `injectModelConfigs(...)`: initializes model adapters from config objects\n- `injectPrismaClient(...)`: installs the shared Prisma client\n\nRepository layout:\n\n- `src/build/`: chunking, graph construction, community detection, registry\n- `src/retrieval/`: query parsing, recall, ranking, evidence selection, answer generation\n- `src/namespace/`: namespace scoping and isolation\n- `src/config/`: default retrieval/build tuning values\n- `examples/`: demo and benchmark scripts\n- `docs/`: architecture and comparison notes\n\n## Tuning and defaults\n\nThe project supports global runtime defaults via `injectGraphRAG(...)`, and request-level overrides via the `retrieve(...)` options object. The production defaults live in `src/config/defaults.ts`.\n\n```ts\nawait injectGraphRAG({\n  retrievalDefaults: {\n    topK: 8,\n    vectorChildTopK: 12,\n    keywordSearchLimit: 24,\n    evidenceChildLimit: 40,\n    rrfK: 80,\n  },\n  buildDefaults: {\n    maxChunkSize: 800,\n    chunkOverlapRatio: 0.1,\n  },\n});\n```\n\nExample per-request tuning:\n\n```ts\nconst result = await service.retrieve({\n  query: 'Who is Irene Adler?',\n  topK: 6,\n  options: {\n    vectorChildTopK: 20,\n    keywordSearchLimit: 30,\n    evidenceChildLimit: 50,\n    rrfK: 80,\n  },\n});\n```\n\nThese knobs control the retrieval window and ranking behavior:\n\n- `topK`: community-level candidate count\n- `vectorChildTopK`: child chunks returned by vector search\n- `keywordSearchLimit`: keyword-matched child chunks\n- `evidenceChildLimit`: evidence merge cap\n- `rrfK`: reciprocal rank fusion sensitivity\n- `maxChunkSize` and `chunkOverlapRatio`: deterministic chunking fallback\n\n## Demo and benchmark\n\n```bash\n# demo build + retrieval\nbun run examples/demo.ts\n\n# benchmark recall metrics\nbun run demo:benchmark\n```\n\nThe benchmark script evaluates retrieval quality against generated Markdown corpora and reports real metrics for the persisted GraphRAG namespace. It is intended to validate the actual build and retrieval pipeline instead of relying on mocked behavior.\n\n## Documentation\n\n- [docs/architecture.md](docs/architecture.md): architecture and data flow\n- [docs/en-US.md](docs/en-US.md): English user guide\n- [docs/zh-CN.md](docs/zh-CN.md): Chinese user guide\n- [docs/comparison.md](docs/comparison.md): comparison notes\n- [CONTRIBUTING.md](CONTRIBUTING.md): contribution guide\n\n## Contributing\n\nContributions are welcome through issues and pull requests. The project is organized around small, testable modules, so the most useful changes usually fit into one of these areas:\n\n- graph construction quality\n- retrieval quality and ranking\n- namespace isolation\n- model-loading robustness\n- documentation and examples\n\n## License\n\nMIT\n","readmeFilename":"README.md"}