快速开始
在服务端调用,把 API Key 放进 PRAXIS_API_KEY 环境变量。下面的例子在 https://api.deepraxis.com 上跑,走完「读类型 → 找到节点 → 读邻域 → 写节点与关系 → 失效一条关系」。
1. 读类型
先看这个组织有哪些已登记的节点类型和关系类型,写入时只能写这里有的名字。
curl "https://api.deepraxis.com/ontology/v1/types" \ -H "Authorization: Bearer $PRAXIS_API_KEY"返回:
{ "data": [ { "owner": "crm", "version": 1, "nodes": [ { "name": "customer", "ref_prefix": "cus_", "weight": 0.6, "passable": true, "description": "A buying customer of the organization." } ], "edges": [ { "name": "references", "source": ["customer"], "target": ["file"], "direction": "forward", "passable": true, "weight": 0.5, "functional": false, "origins": ["platform", "observed"], "description": "A record points at another record it depends on." } ] } ], "next_cursor": null}一个类型要么是节点类型,要么是关系类型。GET /ontology/v1/types/{name} 读单个类型的完整定义,用来确认一个关系类型收下你要写的两端和来源。
2. 按名字找到节点
手里有名字、需要节点 ID 时用检索。返回的是排好序的候选,不是答案。
curl -X POST "https://api.deepraxis.com/ontology/v1/search" \ -H "Authorization: Bearer $PRAXIS_API_KEY" \ -H "Content-Type: application/json" \ -d '{"text":"李总","types":["customer"],"limit":5}'返回:
{ "hits": [ { "node": "ond_0123456789abcdef0123456789abcdef", "score": 0.82, "matched": "name" } ]}matched 说明这个匹配来自哪里:name、alias、description,或节点周围某条关系的 fact。分数只在同一次响应里比较;写入之前先 GET /ontology/v1/nodes/{node_id} 确认拿到的是不是你要的那个实体。
3. 读一个节点的邻域
要一个实体周围的上下文时用邻域读取,不要拉整张图。depth 是走几跳(1–3),limit 是最多返回多少个节点(1–500)。
curl "https://api.deepraxis.com/ontology/v1/nodes/ond_0123456789abcdef0123456789abcdef/neighborhood?depth=2&limit=50" \ -H "Authorization: Bearer $PRAXIS_API_KEY"返回:
{ "nodes": [ { "id": "ond_0123456789abcdef0123456789abcdef", "type": "customer", "name": "李总" } ], "relations": [], "truncated": false}truncated 为真表示节点数到了 limit、遍历提前停下,这时 nodes 是邻域的一个样本而不是全部。邻域不是分页,没有游标可以续读。
4. 建一个节点和一条关系
写操作要带 Idempotency-Key 请求头:同一个键配同样的内容会重放第一次的结果,而不是写第二遍。
curl -X POST "https://api.deepraxis.com/ontology/v1/nodes" \ -H "Authorization: Bearer $PRAXIS_API_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: node-cus_li-1" \ -d '{"type":"customer","ref":"cus_li","name":"李总","aliases":["李总(华东)"],"description":"华东区的采购负责人。"}'返回:
{ "id": "ond_0123456789abcdef0123456789abcdef", "type": "customer", "ref": "cus_li", "name": "李总", "aliases": ["李总(华东)"], "description": "华东区的采购负责人。", "owner": null, "merged_into": null, "created_at": "2026-11-01T00:00:00.000Z", "updated_at": "2026-11-01T00:00:00.000Z", "deleted_at": null}ref 必须匹配该类型的 ref_prefix(这里是 cus_)。接着用两个节点 ID 记一条事实,fact 要能独立读懂:
curl -X POST "https://api.deepraxis.com/ontology/v1/relations" \ -H "Authorization: Bearer $PRAXIS_API_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: relation-cus_li-file_x-1" \ -d '{"type":"references","source":"ond_0123456789abcdef0123456789abcdef","target":"ond_fedcba9876543210fedcba9876543210","fact":"李总的报价单","valid_at":"2026-11-01T00:00:00.000Z"}'返回:
{ "id": "oed_0123456789abcdef0123456789abcdef", "type": "references", "source": "ond_0123456789abcdef0123456789abcdef", "target": "ond_fedcba9876543210fedcba9876543210", "fact": "李总的报价单", "origin": "platform", "confidence": 1, "owner": null, "valid_at": "2026-11-01T00:00:00.000Z", "invalid_at": null, "created_at": "2026-11-01T00:00:00.000Z", "expired_at": null, "superseded_by": null, "archived_at": null}要一次写多条、且只写进去一半会让图不一致时,用 POST /ontology/v1/changesets 把整个批次当作一次事务提交。
5. 失效一条关系
事实不再成立时不要想着删除——图里没有删除。把 invalid_at 移到那个世界时间,关系留在图里,用更早的 as_of 仍然读得到。
curl -X POST "https://api.deepraxis.com/ontology/v1/relations/oed_0123456789abcdef0123456789abcdef/invalidate" \ -H "Authorization: Bearer $PRAXIS_API_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: invalidate-oed_0123456789abcdef-1" \ -d '{"invalid_at":"2026-11-01T12:00:00.000Z","reason":"李总已换供应商"}'返回里 invalid_at 变成你给的时间,expired_at 是平台判定它不再成立的时间,总是晚于 invalid_at。
TypeScript SDK
同一个流程用官方 @deepraxis/sdk 走一遍,方法都在 praxis.ontology.* 下。
import { Praxis } from '@deepraxis/sdk';
const praxis = new Praxis({ apiKey: process.env.PRAXIS_API_KEY! });
// 1. 读类型:写入前先确认名字const types = await praxis.ontology.types.list();for (const item of types.data) console.log(item.owner, item.version);
// 2. 按名字找节点const found = await praxis.ontology.search.create({ body: { text: '李总', types: ['customer'], limit: 5 },});const first = found.hits[0];if (!first) throw new Error('no candidate for 李总');
// 3. 读这个节点周围两跳const neighborhood = await praxis.ontology.nodes.retrieveNeighborhood({ path: { node_id: first.node }, query: { depth: 2, limit: 50 },});console.log(neighborhood.nodes.length, neighborhood.truncated);
// 4. 幂等写入:同一个键重发不会写第二遍const node = await praxis.ontology.nodes.create({ body: { type: 'customer', ref: 'cus_li', name: '李总' }, headers: { 'Idempotency-Key': 'node-cus_li-1' },});const relation = await praxis.ontology.relations.create({ body: { type: 'references', source: node.id, target: 'ond_fedcba9876543210fedcba9876543210', fact: '李总的报价单', }, headers: { 'Idempotency-Key': 'relation-cus_li-file_x-1' },});
// 5. 失效,而不是删除await praxis.ontology.relations.invalidate.create({ path: { relation_id: relation.id }, body: { invalid_at: '2026-11-01T12:00:00.000Z', reason: '李总已换供应商' }, headers: { 'Idempotency-Key': 'invalidate-oed_0123456789abcdef-1' },});列表(praxis.ontology.nodes.list、praxis.ontology.relations.list)返回 Page:直接迭代会按需取下一页,或者把 next_cursor 放进下一次请求。