@neuradex/sdk
v0.1.3
Published
Neuradex SDK for Node.js - Knowledge management and RAG API
Readme
Neuradex SDK
Neuradex APIを利用するためのTypeScript/JavaScript SDK。 Knowledge管理とRAG(セマンティック検索)機能を提供。
インストール
npm install @neuradex/sdk
# または
pnpm add @neuradex/sdk基本的な使い方
import { NdxClient } from '@neuradex/sdk';
const client = new NdxClient({
apiKey: 'ndx_your_api_key',
projectId: 'your-project-id',
});セマンティック検索
// Knowledge検索(タイトル + タグ + メタデータを返却、コンテンツは含まない)
const results = await client.knowledge.search('Reactについて教えて');
for (const result of results) {
console.log(`${result.title} (スコア: ${result.score})`);
console.log(` 概要: ${result.summary}`);
console.log(` トークン数: ${result.contentTokens}`);
console.log(` タグ: ${result.tags.join(', ')}`);
}
// 検索オプション
const results = await client.knowledge.search('認証', { limit: 5 });SearchResultの構造
interface SearchResult {
id: string;
title: string;
tags: string[];
score: number;
summary: string | null; // LLM生成の概要
contentTokens: number | null; // コンテンツのトークン数
createdAt: string | null; // 作成日時
indexedAt: string | null; // インデックス日時
}詳細取得
// フルコンテンツ + 関連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})`);
}検索→詳細取得のパターン
// 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);
}Knowledge CRUD操作
一覧取得
const allKnowledge = await client.knowledge.list();作成
// 単体作成
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'] },
]);更新
// タイトルとコンテンツを更新
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: '更新されたコンテンツ',
});削除
await client.knowledge.delete('knowledge-id');エクスポート
const exported = await client.knowledge.export();
// [{ title: '...', content: '...' }, ...]認証確認
const auth = await client.verifyAuth();
if (auth.valid) {
console.log('認証成功');
} else {
console.error('認証失敗:', auth.error);
}型エクスポート
import type {
NdxClientOptions,
VerifyAuthResult,
Knowledge,
CreateKnowledgeInput,
UpdateKnowledgeInput,
KnowledgeViewResponse,
ConnectedKnowledge,
SearchResult,
SearchResponse,
} from '@neuradex/sdk';開発・テスト
# 環境変数設定(supabase/seed.sqlのテストデータ使用)
cp .env.example .env
# テスト実行
pnpm testライセンス
MIT
