Neuradex SDK for Node.js - Knowledge management and RAG API
npm install @neuradex/sdkNeuradex APIを利用するためのTypeScript/JavaScript SDK。
Knowledge管理とRAG(セマンティック検索)機能を提供。
``bash`
npm install @neuradex/sdkまたは
pnpm add @neuradex/sdk
`typescript
import { NdxClient } from '@neuradex/sdk';
const client = new NdxClient({
apiKey: 'ndx_your_api_key',
projectId: 'your-project-id',
});
`
`typescript
// Knowledge検索(タイトル + タグ + メタデータを返却、コンテンツは含まない)
const results = await client.knowledge.search('Reactについて教えて');
for (const result of results) {
console.log(${result.title} (スコア: ${result.score})); 概要: ${result.summary}
console.log(); トークン数: ${result.contentTokens}
console.log(); タグ: ${result.tags.join(', ')}
console.log();
}
// 検索オプション
const results = await client.knowledge.search('認証', { limit: 5 });
`
`typescript`
interface SearchResult {
id: string;
title: string;
tags: string[];
score: number;
summary: string | null; // LLM生成の概要
contentTokens: number | null; // コンテンツのトークン数
createdAt: string | null; // 作成日時
indexedAt: string | null; // インデックス日時
}
`typescript
// フルコンテンツ + 関連Knowledgeを取得
const detail = await client.knowledge.get('knowledge-id');
console.log(detail.title);
console.log(detail.content);
console.log(detail.tags);
// 関連Knowledge
for (const connected of detail.connectedKnowledge) {
console.log(関連: ${connected.title} (${connected.relationType}));`
}
`typescript
// 1. 検索でタイトルを取得
const results = await client.knowledge.search('Reactのフック');
// 2. 上位の結果から詳細を取得
if (results.length > 0) {
const detail = await client.knowledge.get(results[0].id);
console.log(detail.content);
}
`
`typescript`
const allKnowledge = await client.knowledge.list();
`typescript
// 単体作成
const knowledge = await client.knowledge.create({
title: 'Reactの基本',
content: 'Reactは...',
tags: ['react', 'frontend'],
});
// 一括作成
const items = await client.knowledge.bulkCreate([
{ title: 'Item 1', content: 'Content 1', tags: ['tag1'] },
{ title: 'Item 2', content: 'Content 2', tags: ['tag2'] },
]);
`
`typescript
// タイトルとコンテンツを更新
const updated = await client.knowledge.update('knowledge-id', {
title: '新しいタイトル',
content: '更新されたコンテンツ',
});
// タイトルのみ更新
const updated = await client.knowledge.update('knowledge-id', {
title: '新しいタイトル',
});
// コンテンツのみ更新
const updated = await client.knowledge.update('knowledge-id', {
content: '更新されたコンテンツ',
});
`
`typescript`
await client.knowledge.delete('knowledge-id');
`typescript`
const exported = await client.knowledge.export();
// [{ title: '...', content: '...' }, ...]
`typescript`
const auth = await client.verifyAuth();
if (auth.valid) {
console.log('認証成功');
} else {
console.error('認証失敗:', auth.error);
}
`typescript`
import type {
NdxClientOptions,
VerifyAuthResult,
Knowledge,
CreateKnowledgeInput,
UpdateKnowledgeInput,
KnowledgeViewResponse,
ConnectedKnowledge,
SearchResult,
SearchResponse,
} from '@neuradex/sdk';
`bash環境変数設定(supabase/seed.sqlのテストデータ使用)
cp .env.example .env
MIT