[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-114637":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":17,"stars7d":18,"stars30d":19,"stars90d":16,"forks30d":16,"starsTrendScore":20,"compositeScore":21,"rankGlobal":10,"rankLanguage":10,"license":22,"archived":23,"fork":23,"defaultBranch":24,"hasWiki":25,"hasPages":23,"topics":26,"createdAt":10,"pushedAt":33,"updatedAt":34,"readmeContent":35,"aiSummary":36,"trendingCount":16,"starSnapshotCount":16,"syncStatus":37,"lastSyncTime":38,"discoverSource":39},114637,"selfgraph","hydra-db\u002Fselfgraph","hydra-db","Build and query versioned knowledge graphs for AI agents, with any graph database.","https:\u002F\u002Fgithub.com\u002Fhydra-db\u002Fselfgraph",null,"TypeScript",232,76,1,34,0,8,141,165,83,91.63,"Apache License 2.0",false,"main",true,[27,28,29,30,31,32],"agent","graphs","knowledge-graph","knowledge-graphs","knowledge-management","ontology","2026-11-23 19:49:49","2026-11-23 19:31:31","\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Fraw.githubusercontent.com\u002Fhydra-db\u002Fselfgraph\u002Fmain\u002Fassets\u002Flogo.png\" alt=\"SelfGraph\" width=\"92\" \u002F>\n\u003C\u002Fp>\n\n\u003Ch1 align=\"center\">SelfGraph\u003C\u002Fh1>\n\n\u003Cp align=\"center\">\n  \u003Cb>Turn unstructured text into a queryable, versioned knowledge graph.\u003C\u002Fb>\u003Cbr\u002F>\n  One SDK for graphs and ontologies, over any graph database, in Python and TypeScript.\n\u003C\u002Fp>\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpython-3.10%2B-3776AB?logo=python&logoColor=white\" alt=\"Python 3.10+\" \u002F>\n  \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fnode-20%2B-3178C6?logo=typescript&logoColor=white\" alt=\"TypeScript, Node 20+\" \u002F>\n  \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Flicense-Apache--2.0-3DA639\" alt=\"License Apache-2.0\" \u002F>\n  \u003Ca href=\"https:\u002F\u002Fdiscord.gg\u002FHcBKJHXmnu\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FDiscord-join-5865F2?logo=discord&logoColor=white\" alt=\"Discord\" \u002F>\u003C\u002Fa>\n\u003C\u002Fp>\n\n## Why SelfGraph\n\n- **Text in, graph out.** Extract entities and relations with any LLM, or without one.\n- **Any graph database.** Neo4j, Memgraph, FalkorDB, HydraDB, or embedded Kuzu, behind one API.\n- **Facts that change.** Every change is versioned, newer facts retire older ones, and you can read the graph as of any past time, or as it was known then.\n- **An ontology, not just a graph.** Types, synonyms, and definitions ground a question, so the answerability check knows a firm is a `Company`.\n- **Light by default, powerful on request.** One `level` option moves every capability from free and deterministic to LLM-backed.\n- **Knows when it has no answer.** An LLM-free answerability check, readiness lint, and certified facts tell an agent what the graph holds.\n- **No vector store.** Retrieval walks the graph from keyword matches and returns the source passages. Embeddings are optional.\n- **SDK, CLI, and MCP server** over the same graph, in Python and TypeScript.\n\n## Install\n\n```bash\npip install selfgraph            # Neo4j, Memgraph, and HydraDB\npip install \"selfgraph[all]\"     # plus LLM extraction, Kuzu, FalkorDB, spaCy, tiktoken, and MCP\n```\n\nEvery extra is listed in [install](https:\u002F\u002Fgithub.com\u002Fhydra-db\u002Fselfgraph\u002Fblob\u002Fmain\u002Fdocs\u002Finstall.md). For TypeScript, see [typescript\u002FREADME.md](https:\u002F\u002Fgithub.com\u002Fhydra-db\u002Fselfgraph\u002Fblob\u002Fmain\u002Ftypescript\u002FREADME.md).\n\n## Quickstart\n\nNo server and no LLM, with `pip install \"selfgraph[kuzu]\"`:\n\n```python\nimport asyncio\n\nfrom selfgraph import KuzuStore, SelfGraph\n\n\nasync def main() -> None:\n    async with SelfGraph(store=KuzuStore(\"graph.kuzu\")) as graph:\n        await graph.insert.facts(\n            {\n                \"entities\": [\n                    {\"id\": \"person:jane\", \"type\": \"Person\", \"name\": \"Jane Doe\"},\n                    {\"id\": \"company:acme\", \"type\": \"Company\", \"name\": \"Acme\"},\n                ],\n                \"relations\": [\n                    {\"from_entity\": \"person:jane\", \"type\": \"WORKS_AT\", \"to_entity\": \"company:acme\"},\n                ],\n            }\n        )\n        result = await graph.retrieve(\"who works at Acme\")\n        print(result.context)\n\n\nasyncio.run(main())\n```\n\nWith an LLM and a server:\n\n```python\nfrom selfgraph import LLMConfig, Neo4jStore, SelfGraph\n\nasync with SelfGraph(\n    store=Neo4jStore(\"bolt:\u002F\u002Flocalhost:7687\", auth=(\"neo4j\", \"password\")),\n    llm=LLMConfig(provider=\"anthropic\", model=\"claude-sonnet-5-5\"),\n) as graph:\n    await graph.insert.text(\"Soham prefers HydraDB. The team picked it for temporal history.\")\n    result = await graph.retrieve(\"which database and why\")\n    print(result.context)\n```\n\n`SyncSelfGraph` has the same API without `await`. Without an LLM, `insert.text` falls back to spaCy or a simple regex pass; see [inserting](https:\u002F\u002Fgithub.com\u002Fhydra-db\u002Fselfgraph\u002Fblob\u002Fmain\u002Fdocs\u002Finserting.md).\n\n## Levels\n\nEvery capability is a ladder of tiers, and `level` sets them all. The default, `balanced`, is the strongest tier that is free and deterministic.\n\n| Capability | `light` | `balanced` (default) | `max` |\n|------------|---------|----------------------|-------|\n| Extraction | regex | spaCy, else regex | LLM |\n| Entity resolution | derived ids | name and alias match | LLM-confirmed |\n| Contradictions | warn on schema limits | warn on schema limits | LLM-judged, no schema needed |\n| Retrieval seeds | BM25 | BM25 plus schema synonyms | plus embeddings, with your embedder |\n| Traversal | BFS | BFS | PageRank |\n\n```python\ngraph = SelfGraph(store=store, llm=llm, level=\"max\")  # everything on\ngraph = SelfGraph(store=store, llm=llm, contradiction=\"llm\")  # one capability\ngraph = SelfGraph(store=store, llm=llm, level=\"max\", max_tier=\"balanced\")  # cap: no LLM calls\nprint(graph.tiers)\n```\n\n- Passing `llm=` turns on LLM extraction only. Every other LLM tier is opt-in.\n- A higher tier runs the lower ones first and sends only the undecided cases up, so cost follows the hard cases.\n- Every tier writes the same ids and encoding. Changing a tier needs no migration.\n- Each result reports the tiers that produced it in `result.tiers`.\n\nSee [tiers](https:\u002F\u002Fgithub.com\u002Fhydra-db\u002Fselfgraph\u002Fblob\u002Fmain\u002Fdocs\u002Ftiers.md).\n\n## Facts that change\n\nA newer fact can retire an older one. Declare the rule in a schema, or let an LLM judge it with no schema:\n\n```python\ngraph = SelfGraph(store=store, llm=llm, contradiction=\"llm\")\nawait graph.relations.create(\"person:ann\", \"WORKS_AT\", \"company:acme\", event_time=\"2020-01-01\")\nawait graph.relations.create(\"person:ann\", \"WORKS_AT\", \"company:globex\", event_time=\"2022-01-01\")\n\nawait graph.retrieve(\"where does Ann work\")  # Globex\nawait graph.retrieve(\"where does Ann work\", as_of=\"2021-06-01\")  # Acme\n```\n\nNothing is deleted. The retired relation keeps its history and records what replaced it. See [contradictions](https:\u002F\u002Fgithub.com\u002Fhydra-db\u002Fselfgraph\u002Fblob\u002Fmain\u002Fdocs\u002Fschema.md#contradictions).\n\n## Ontology\n\nA schema can carry synonyms, certified definitions, and where each term's data lives. `check_answerable` then grounds a question in those terms before an agent answers:\n\n```python\nschema = {\n    \"entities\": [\n        {\n            \"name\": \"Company\",\n            \"synonyms\": [\"employer\", \"firm\"],\n            \"definitions\": [{\"name\": \"headcount\", \"expression\": \"count(Person)\", \"synonyms\": [\"staff size\"]}],\n        }\n    ]\n}\ngraph = SelfGraph(store=store, schema=schema)\nawait graph.insert.facts({\"entities\": [{\"name\": \"Acme\", \"type\": \"Company\"}]})\n\nreport = await graph.check_answerable(\"What is the staff size of the firm Acme by ad spend?\")\nreport.missing  # [\"ad\", \"spend\"]\nawait graph.retrieve(\"which employers\")  # seeds Company entities through the synonym\n```\n\n`Schema.from_tables` drafts a schema from table and column metadata, with no database connection. See [ontology](https:\u002F\u002Fgithub.com\u002Fhydra-db\u002Fselfgraph\u002Fblob\u002Fmain\u002Fdocs\u002Fontology.md).\n\n## Backends\n\n```python\nfrom selfgraph import CypherStore, FalkorDBStore, HydraDBStore, KuzuStore, Neo4jStore\n\nNeo4jStore(\"bolt:\u002F\u002Flocalhost:7687\", auth=(\"neo4j\", \"password\"))\nCypherStore(\"bolt:\u002F\u002Flocalhost:7687\", auth=(\"user\", \"password\"))  # Memgraph and other Bolt engines\nFalkorDBStore(host=\"localhost\", port=6379)\nKuzuStore(\"graph.kuzu\")  # embedded\nHydraDBStore(\"bolt:\u002F\u002F127.0.0.1:17687\", auth=(\"neo4j\", \"\u003Ctoken>\"))  # HydraDB 0.4.0 or newer\n```\n\nSee [backends](https:\u002F\u002Fgithub.com\u002Fhydra-db\u002Fselfgraph\u002Fblob\u002Fmain\u002Fdocs\u002Fbackends.md) to configure from settings or add your own store.\n\n## CLI and MCP\n\n```bash\nexport SELFGRAPH_AUTH=neo4j:password\nselfgraph --store neo4j --uri bolt:\u002F\u002Flocalhost:7687 insert text \"Jane runs Acme.\" --source-id notes\nselfgraph --store neo4j --uri bolt:\u002F\u002Flocalhost:7687 retrieve \"who runs Acme\" --context-only\n```\n\n`selfgraph mcp` serves the same API as MCP tools. Stdio clients do not pass your shell environment, so set the connection in `env`:\n\n```json\n{\n  \"mcpServers\": {\n    \"selfgraph\": {\n      \"command\": \"selfgraph\",\n      \"args\": [\"mcp\"],\n      \"env\": {\n        \"SELFGRAPH_STORE\": \"neo4j\",\n        \"SELFGRAPH_URI\": \"bolt:\u002F\u002Flocalhost:7687\",\n        \"SELFGRAPH_AUTH\": \"neo4j:password\"\n      }\n    }\n  }\n}\n```\n\n## Documentation\n\n- [Install](https:\u002F\u002Fgithub.com\u002Fhydra-db\u002Fselfgraph\u002Fblob\u002Fmain\u002Fdocs\u002Finstall.md) and [quickstart](https:\u002F\u002Fgithub.com\u002Fhydra-db\u002Fselfgraph\u002Fblob\u002Fmain\u002Fdocs\u002Fquickstart.md)\n- [Inserting](https:\u002F\u002Fgithub.com\u002Fhydra-db\u002Fselfgraph\u002Fblob\u002Fmain\u002Fdocs\u002Finserting.md): text, facts, LLM setup, custom prompts\n- [Tiers](https:\u002F\u002Fgithub.com\u002Fhydra-db\u002Fselfgraph\u002Fblob\u002Fmain\u002Fdocs\u002Ftiers.md): the `level` preset and the cost cap\n- [Schema](https:\u002F\u002Fgithub.com\u002Fhydra-db\u002Fselfgraph\u002Fblob\u002Fmain\u002Fdocs\u002Fschema.md): types, validation, contradictions, Neo4j interop, Ossie export\n- [Ontology](https:\u002F\u002Fgithub.com\u002Fhydra-db\u002Fselfgraph\u002Fblob\u002Fmain\u002Fdocs\u002Fontology.md): terms, synonyms, grounding a question, drafts from table metadata\n- [Entity resolution](https:\u002F\u002Fgithub.com\u002Fhydra-db\u002Fselfgraph\u002Fblob\u002Fmain\u002Fdocs\u002Fresolution.md): merging duplicates\n- [Resources](https:\u002F\u002Fgithub.com\u002Fhydra-db\u002Fselfgraph\u002Fblob\u002Fmain\u002Fdocs\u002Fresources.md): entities, relations, preferences, decisions, ids\n- [Retrieval](https:\u002F\u002Fgithub.com\u002Fhydra-db\u002Fselfgraph\u002Fblob\u002Fmain\u002Fdocs\u002Fretrieval.md) and [maintenance](https:\u002F\u002Fgithub.com\u002Fhydra-db\u002Fselfgraph\u002Fblob\u002Fmain\u002Fdocs\u002Fmaintenance.md)\n- [Answering safely](https:\u002F\u002Fgithub.com\u002Fhydra-db\u002Fselfgraph\u002Fblob\u002Fmain\u002Fdocs\u002Ftrust.md): readiness, answerability, hubs, certified facts\n- [Backends](https:\u002F\u002Fgithub.com\u002Fhydra-db\u002Fselfgraph\u002Fblob\u002Fmain\u002Fdocs\u002Fbackends.md), [CLI](https:\u002F\u002Fgithub.com\u002Fhydra-db\u002Fselfgraph\u002Fblob\u002Fmain\u002Fdocs\u002Fcli.md), [MCP](https:\u002F\u002Fgithub.com\u002Fhydra-db\u002Fselfgraph\u002Fblob\u002Fmain\u002Fdocs\u002Fmcp.md), [errors](https:\u002F\u002Fgithub.com\u002Fhydra-db\u002Fselfgraph\u002Fblob\u002Fmain\u002Fdocs\u002Ferrors.md), [TypeScript](https:\u002F\u002Fgithub.com\u002Fhydra-db\u002Fselfgraph\u002Fblob\u002Fmain\u002Fdocs\u002Ftypescript.md)\n\n## Contributing\n\nContributions start with an approved issue; see [CONTRIBUTING.md](https:\u002F\u002Fgithub.com\u002Fhydra-db\u002Fselfgraph\u002Fblob\u002Fmain\u002FCONTRIBUTING.md). Join us on [Discord](https:\u002F\u002Fdiscord.gg\u002FHcBKJHXmnu).\n\n## License\n\nApache-2.0.\n","SelfGraph 是一个用于构建和查询版本化知识图谱的开源 SDK，支持多种图数据库后端。它提供统一 API 实现文本到图谱的结构化转换，支持实体关系抽取（可选 LLM 或规则驱动）、基于本体的语义建模、时间点快照式版本控制，以及无需向量库的图内检索。其轻量默认设计兼顾确定性与可扩展性，适合 AI 代理系统、企业知识管理、动态事实追踪等需长期维护、可审计、可回溯的知识建模场景。",2,"2026-11-24 04:49:16","CREATED_QUERY"]