本页还没有译文
本页 27 段还没译成日本語,下面显示的是英文原文。Nia
还没翻译译自英文(ai-sdk.dev)本页 27 段都还没译
Nia by Nozomio Labs is an API for technical, up-to-date context. It lets you index docs, repos, PDFs, and datasets, then search them with AI so your agent gets real answers instead of hallucinations. The @nozomioai/nia-ai-sdk package integrates Nia with the AI SDK through tools, middleware, and direct streaming helpers.
It is designed for workflows where you want to:
- Call Nia Tracer as a tool for public GitHub and documentation research
- Call Nia Oracle as a tool for grounded research over indexed repositories, docs, PDFs, and datasets
- Call Nia Document Agent as a tool for deep document analysis and structured extraction
- Augment an existing AI SDK model with Nia-backed middleware
- Stream Tracer, Oracle, or Document Agent events directly in your app
Learn more in the Nia documentation.
Setup
The Nia adapter is available in the @nozomioai/nia-ai-sdk package. You can install it with:
pnpm add @nozomioai/nia-ai-sdknpm install @nozomioai/nia-ai-sdkyarn add @nozomioai/nia-ai-sdkbun add @nozomioai/nia-ai-sdkIf you want to use Nia middleware with a model provider, install that provider as well. For example:
pnpm add @ai-sdk/openaiSet your Nia API key:
export NIA_API_KEY=nia_your_api_keyYou can get your API key from the Nia dashboard.
Tool Usage
Nia works well as a set of AI SDK tools that you pass to generateText or streamText.
generateText
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { createNiaResearchTools } from '@nozomioai/nia-ai-sdk';
const tools = createNiaResearchTools({
apiKey: process.env.NIA_API_KEY!,
tracer: {
defaultRequest: {
mode: 'tracer-deep',
},
},
oracle: {
defaultRequest: {
repositories: ['vercel/ai'],
dataSources: ['Vercel AI SDK'],
},
},
documentAgent: {
defaultRequest: {
sourceId: 'src_abc123',
},
},
});
const result = await generateText({
model: openai('gpt-4.1'),
prompt:
'Research how AI SDK middleware works, then summarize the best integration pattern.',
tools,
});
console.log(result.text);You can pass false to any service key to disable it entirely, e.g. oracle: false if you only need Tracer. Per-service transport options (such as a separate apiKey) override the top-level ones when provided.
The SDK also exports createTracerTool(), createOracleTool(), and createDocumentAgentTool() for when you only need a single tool.
Middleware Usage
Use middleware when you want Nia to enrich the last user message before your base model runs.
withOracleContext
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { withOracleContext } from '@nozomioai/nia-ai-sdk';
const model = withOracleContext(openai('gpt-4.1'), {
apiKey: process.env.NIA_API_KEY!,
defaultRequest: {
repositories: ['vercel/ai'],
dataSources: ['Vercel AI SDK'],
},
});
const result = await generateText({
model,
prompt: 'How should I think about AI SDK middleware for retrieval?',
});
console.log(result.text);You can use withTracerContext() in the same way for public GitHub research and withDocumentAgentContext() when working with indexed PDFs or documents.
For more control, the lower-level createTracerMiddleware(), createOracleMiddleware(), and createDocumentAgentMiddleware() exports return raw LanguageModelMiddleware objects you can compose yourself.
Direct Streaming Helpers
If you want raw Nia job events, use the direct streaming helpers:
streamTracer()streamOracle()streamOracleSessionChat()streamDocumentAgent()
import { streamTracer } from '@nozomioai/nia-ai-sdk';
const session = await streamTracer(
{
apiKey: process.env.NIA_API_KEY!,
},
{
query: 'How does generateText stream responses?',
repositories: ['vercel/ai'],
mode: 'tracer-fast',
},
);
for await (const event of session.events) {
console.log(event.event, event.data);
}