Entities APIは、プロジェクト内のエンティティ(人物、企業、製品、場所など)を管理するためのインターフェースです。
const client = new NdxClient({
apiKey: process.env.NEURADEX_API_KEY,
projectId: 'your-project-id',
});
// Entities APIにアクセス
const entities = await client.entities.list();
const entity = await client.entities.create({
canonicalName: '山田太郎',
type: 'person',
});
メソッド一覧
| メソッド | 説明 |
|---|
list(options?) | エンティティ一覧を取得 |
get(entityId) | 特定のエンティティを取得 |
create(input) | エンティティを作成 |
update(entityId, input) | エンティティを更新 |
delete(entityId) | エンティティを削除 |
getAliases(entityId) | エイリアス一覧を取得 |
addAlias(entityId, alias) | エイリアスを追加 |
removeAlias(entityId, aliasId) | エイリアスを削除 |
getRelations(entityId) | 関係を取得 |
addRelation(entityId, targetId, type) | 関係を追加 |
removeRelation(entityId, relationId) | 関係を削除 |
getKnowledges(entityId) | 関連Knowledgeを取得 |
getTopics(entityId) | 関連Topicを取得 |
getEpisodes(entityId) | 関連Episodeを取得 |
findSimilar(options?) | 類似エンティティを検出 |
merge(input) | エンティティをマージ |
getGraph() | 関係グラフを取得 |
エンティティタイプ
| タイプ | 説明 |
|---|
person | 人物 |
company | 企業・組織 |
product | 製品・サービス |
place | 場所 |
other | その他 |
list()
エンティティ一覧を取得します。
パラメータ
エンティティタイプでフィルタ: 'person' | 'company' | 'product' | 'place' | 'other'
使用例
// 全エンティティを取得
const result = await client.entities.list();
console.log(`エンティティ数: ${result.total}`);
// 人物のみ
const people = await client.entities.list({ type: 'person' });
// 検索
const results = await client.entities.list({ search: '山田' });
get()
特定のエンティティを取得します(エイリアス含む)。
パラメータ
使用例
const entity = await client.entities.get('entity-id');
console.log(`名前: ${entity.canonicalName}`);
console.log(`タイプ: ${entity.type}`);
console.log(`エイリアス: ${entity.aliases.map(a => a.alias).join(', ')}`);
create()
新しいエンティティを作成します。
パラメータ
エンティティタイプ: 'person' | 'company' | 'product' | 'place' | 'other'
使用例
const entity = await client.entities.create({
canonicalName: '山田太郎',
type: 'person',
aliases: ['山田さん', 'Taro Yamada'],
});
console.log(`作成: ${entity.id}`);
update()
エンティティを更新します。
パラメータ
使用例
const updated = await client.entities.update('entity-id', {
canonicalName: '山田太郎(部長)',
});
delete()
エンティティを削除します。
使用例
await client.entities.delete('entity-id');
addAlias()
エンティティにエイリアスを追加します。
パラメータ
作成元: 'user' | 'llm' | 'import'
使用例
const alias = await client.entities.addAlias('entity-id', '太郎');
removeAlias()
エイリアスを削除します。
使用例
await client.entities.removeAlias('entity-id', 'alias-id');
getRelations()
エンティティの関係(発信・受信)を取得します。
使用例
const relations = await client.entities.getRelations('entity-id');
// 発信(このエンティティから他へ)
for (const rel of relations.outgoing) {
console.log(`${rel.relationType} → ${rel.targetEntity.canonicalName}`);
}
// 受信(他からこのエンティティへ)
for (const rel of relations.incoming) {
console.log(`${rel.sourceEntity.canonicalName} → ${rel.relationType}`);
}
addRelation()
エンティティ間の関係を追加します。
パラメータ
関係タイプ
| タイプ | 説明 |
|---|
works_for | 〜で働いている |
employs | 〜を雇用している |
member_of | 〜のメンバー |
owns | 〜を所有 |
partner_of | 〜のパートナー |
competitor_of | 〜の競合 |
subsidiary_of | 〜の子会社 |
parent_company_of | 〜の親会社 |
located_in | 〜に所在 |
related_to | 〜に関連 |
使用例
const relation = await client.entities.addRelation(
'person-entity-id',
'company-entity-id',
'works_for'
);
getKnowledges()
エンティティに関連するKnowledgeを取得します。
使用例
const result = await client.entities.getKnowledges('entity-id');
for (const k of result.knowledges) {
console.log(`${k.knowledgeTitle}: "${k.mentionText}"`);
}
getTopics()
エンティティに関連するTopicを取得します。
使用例
const result = await client.entities.getTopics('entity-id');
for (const t of result.topics) {
console.log(`${t.topicTitle}: "${t.mentionText}"`);
}
getEpisodes()
エンティティに関連するEpisodeを取得します。
使用例
const result = await client.entities.getEpisodes('entity-id');
for (const e of result.episodes) {
console.log(`"${e.mentionText}" in episode`);
}
findSimilar()
類似したエンティティを検出します(重複検出)。
パラメータ
使用例
const pairs = await client.entities.findSimilar();
for (const pair of pairs) {
console.log(`類似: ${pair.entity1.canonicalName} ↔ ${pair.entity2.canonicalName}`);
console.log(`スコア: ${pair.similarity}`);
}
merge()
2つのエンティティをマージ(統合)します。
パラメータ
使用例
const result = await client.entities.merge({
keepEntityId: 'entity-1',
mergeEntityId: 'entity-2',
});
console.log(`マージ完了:`);
console.log(`- エイリアス: ${result.mergedAliases}件`);
console.log(`- Knowledge: ${result.migratedKnowledges}件`);
console.log(`- Episode: ${result.migratedEpisodes}件`);
getGraph()
エンティティの関係グラフを取得します。
使用例
const graph = await client.entities.getGraph();
console.log(`ノード数: ${graph.nodes.length}`);
console.log(`エッジ数: ${graph.edges.length}`);
// ノード
for (const node of graph.nodes) {
console.log(`${node.canonicalName} (${node.type})`);
}
// エッジ
for (const edge of graph.edges) {
console.log(`${edge.source} --${edge.relationType}--> ${edge.target}`);
}
次のステップ