Skip to main content

Overview

In this guide, you will:
  1. Register knowledge
  2. Execute semantic search
  3. Build RAG with Chat API

Setup

1

Install the SDK

If you haven’t already, install the SDK.
npm install @neuradex/sdk
2

Initialize the Client

import { NdxClient } from '@neuradex/sdk';

const client = new NdxClient({
  apiKey: process.env.NEURADEX_API_KEY,
  projectId: process.env.NEURADEX_PROJECT_ID,
});

Registering Knowledge

Knowledge consists of title, content, and tags.
// Create a single knowledge entry
const knowledge = await client.knowledge.create({
  title: 'Return Policy',
  content: `
    Returns are accepted within 30 days of product arrival.

    Return conditions:
    - Item must be unused and unopened
    - Tags must still be attached
    - Receipt or order confirmation email required

    Return process:
    1. Submit return request from My Page
    2. Print the return shipping label
    3. Package and ship the item
  `,
  tags: ['returns', 'policy', 'customer-support'],
});

console.log(`Created: ${knowledge.id}`);

Bulk Registration

You can also register multiple knowledge entries at once.
const items = await client.knowledge.bulkCreate([
  {
    title: 'Shipping Information',
    content: 'Standard shipping takes 3-5 business days. Express shipping delivers next day.',
    tags: ['shipping', 'FAQ'],
  },
  {
    title: 'Payment Methods',
    content: 'We accept credit cards, bank transfers, and convenience store payments.',
    tags: ['payment', 'FAQ'],
  },
]);
Search registered knowledge using natural language.
// Execute search
const results = await client.knowledge.search('I want to return a product');

// Display results
for (const result of results) {
  console.log(`${result.title} (score: ${result.score})`);
  console.log(`  Summary: ${result.summary}`);
  console.log(`  Tags: ${result.tags.join(', ')}`);
}
search() returns only title, tags, and score. Use get() for full content.

Get Details

Retrieve details from search results.
// Get details of the most relevant result
if (results.length > 0) {
  const detail = await client.knowledge.get(results[0].id);

  console.log(detail.title);
  console.log(detail.content);

  // Check related knowledge
  for (const connected of detail.connectedKnowledge) {
    console.log(`Related: ${connected.title}`);
  }
}

Building RAG with Chat API

The Chat API is the recommended way to use your knowledge. It handles context retrieval, prompt construction, and LLM calls in one step.
Chat API automatically handles context retrieval, prompt construction, and LLM calls internally. Just set memory: { enabled: true } and your knowledge-powered RAG is complete.
import { NdxClient } from '@neuradex/sdk';

const client = new NdxClient({
  apiKey: process.env.NEURADEX_API_KEY,
  projectId: process.env.NEURADEX_PROJECT_ID,
});

// RAG in one step — SDK handles memory retrieval and prompt construction
const stream = client.chat.create({
  model: 'gpt-4o',
  messages: [
    {
      role: 'system',
      content: 'You are a customer support assistant.',
    },
    {
      role: 'user',
      content: 'How do I return a product?',
    },
  ],
  memory: { enabled: true, maxTokens: 4000, includeEpisodes: true },
});

// Stream responses in real-time
for await (const chunk of stream.textStream) {
  process.stdout.write(chunk);
}

Next Steps

Chat API

Chat Completions with memory

Knowledge API

Detailed knowledge operations

Memory API

Context assembly details