> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wazoo.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# AI SDK

> Connect Worlds knowledge graphs to Vercel AI SDK

The [Vercel AI SDK](https://sdk.vercel.ai/) is the TypeScript toolkit for
building AI applications with React, Svelte, and Vue. The Wazoo AI tools package
(`@wazoo/tools`) exposes tools that let LLMs [search](/worlds/search) and
[query](/worlds/query) `@worlds/sdk` knowledge graphs.

## Installation

Install the Wazoo AI Tools from JSR:

<CodeGroup>
  ```bash npm theme={null}
  npx jsr add @wazoo/tools
  ```

  ```bash deno theme={null}
  deno add jsr:@wazoo/tools
  ```

  ```bash pnpm theme={null}
  pnpm dlx jsr add @wazoo/tools
  ```

  ```bash yarn theme={null}
  yarn dlx jsr add @wazoo/tools
  ```

  ```bash bun theme={null}
  bunx jsr add @wazoo/tools
  ```
</CodeGroup>

## Usage

The tools are designed to work with the
[Vercel AI SDK](https://sdk.ai/docs/ai-sdk-core/tools-and-tool-calling).

```typescript theme={null}
import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";
import { Client } from "@worlds/sdk";
import { ComunicaSparqlEngine } from "@worlds/sdk/comunica";
import { RdfjsQuadStore, RdfjsSearchIndex } from "@worlds/sdk/rdfjs";
import { QueryEngine } from "@comunica/query-sparql-rdfjs-lite";
import { Store } from "n3";
import { createTools } from "@wazoo/tools";

const store = new Store();
const client = new Client({
  quadStore: new RdfjsQuadStore(store),
  searchIndex: new RdfjsSearchIndex(store),
  sparqlEngine: new ComunicaSparqlEngine({
    queryEngine: new QueryEngine(),
    store,
  }),
});

const tools = createTools({
  client,
  sources: ["my-world"],
});

const { text } = await generateText({
  model: openai("gpt-4o"),
  tools,
  prompt: "Find all people in the knowledge base and describe them.",
});
```

## Tools

The `createTools` function returns a full toolset for use with LLM frameworks.

### Individual tools

If you require granular control, you can import and initialize tools
individually:

```typescript theme={null}
import {
  createDiscoverSchemaTool,
  createExecuteSparqlTool,
  createSearchEntitiesTool,
  createImportRdfTool,
  createExportRdfTool,
} from "@wazoo/tools";

// client is the @worlds/sdk instance from the usage example above.
const discoverSchema = createDiscoverSchemaTool(client, {
  sources: ["my-world"],
});
const executeSparql = createExecuteSparqlTool(client);
const searchEntities = createSearchEntitiesTool(client);
const importRdf = createImportRdfTool(client);
const exportRdf = createExportRdfTool(client);

const tools = {
  discoverSchema,
  executeSparql,
  searchEntities,
  importRdf,
  exportRdf,
};
```

### Tool reference

| Tool             | Description                                                |
| :--------------- | :--------------------------------------------------------- |
| `executeSparql`  | Direct execution of SPARQL queries (read-only by default). |
| `searchEntities` | Vector and keyword search for entities within a graph.     |
| `discoverSchema` | Explore the ontology and schema of a specific world.       |
| `importRdf`      | Utility for ingesting RDF triples into a world graph.      |
| `exportRdf`      | Utility for exporting RDF triples from a world graph.      |
