@vectorize-io/hindsight-ai-sdk 0.4.9 → 0.4.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,313 +2,61 @@
2
2
 
3
3
  Give your AI agents persistent, human-like memory using [Hindsight](https://vectorize.io/hindsight) with the [Vercel AI SDK](https://ai-sdk.dev).
4
4
 
5
- ## Features
6
-
7
- - **Three Memory Operations**: `retain` (store), `recall` (retrieve), and `reflect` (reason over memories)
8
- - **Multi-User Support**: Dynamic bank IDs per call for multi-user/multi-tenant scenarios
9
- - **Full API Coverage**: Complete parameter support for all Hindsight operations
10
- - **Type-Safe**: Full TypeScript support with Zod schemas for validation
11
- - **AI SDK 6 Native**: Works seamlessly with `generateText`, `streamText`, and `ToolLoopAgent`
12
-
13
- ## Installation
14
-
15
- ```bash
16
- npm install @vectorize-io/hindsight-ai-sdk ai zod
17
- ```
18
-
19
- You'll also need a Hindsight client. Choose one:
5
+ ## Quick Start
20
6
 
21
- **Option A: TypeScript/JavaScript Client**
22
7
  ```bash
23
- npm install @vectorize-io/hindsight-client
8
+ npm install @vectorize-io/hindsight-ai-sdk @vectorize-io/hindsight-client ai zod
24
9
  ```
25
10
 
26
- **Option B: Direct HTTP Client** (no additional dependencies)
27
- ```typescript
28
- // See "HTTP Client Example" below
29
- ```
30
-
31
- ## Quick Start
32
-
33
- ### 1. Set up your Hindsight client
34
-
35
11
  ```typescript
36
12
  import { HindsightClient } from '@vectorize-io/hindsight-client';
37
-
38
- const hindsightClient = new HindsightClient({
39
- apiUrl: process.env.HINDSIGHT_API_URL || 'http://localhost:8000',
40
- });
41
- ```
42
-
43
- ### 2. Create Hindsight tools
44
-
45
- ```typescript
46
13
  import { createHindsightTools } from '@vectorize-io/hindsight-ai-sdk';
47
-
48
- const tools = createHindsightTools({
49
- client: hindsightClient,
50
- });
51
- ```
52
-
53
- ### 3. Use with AI SDK
54
-
55
- ```typescript
56
14
  import { generateText } from 'ai';
57
15
  import { anthropic } from '@ai-sdk/anthropic';
58
16
 
59
- const result = await generateText({
60
- model: anthropic('claude-sonnet-4-20250514'),
61
- tools,
62
- prompt: 'Remember that Alice loves hiking and prefers spicy food',
63
- });
64
-
65
- console.log(result.text);
66
- ```
67
-
68
- ## Full Example: Memory-Enabled Chatbot
69
-
70
- ```typescript
71
- import { HindsightClient } from '@vectorize-io/hindsight-client';
72
- import { createHindsightTools } from '@vectorize-io/hindsight-ai-sdk';
73
- import { streamText } from 'ai';
74
- import { anthropic } from '@ai-sdk/anthropic';
75
-
76
- // Initialize Hindsight
17
+ // 1. Initialize Hindsight client
77
18
  const hindsightClient = new HindsightClient({
78
19
  apiUrl: 'http://localhost:8000',
79
20
  });
80
21
 
22
+ // 2. Create memory tools
81
23
  const tools = createHindsightTools({ client: hindsightClient });
82
24
 
83
- // Chat with memory
84
- const result = await streamText({
85
- model: anthropic('claude-sonnet-4-20250514'),
86
- tools,
87
- system: `You are a helpful assistant with long-term memory.
88
-
89
- IMPORTANT:
90
- - Before answering questions, use the 'recall' tool to check for relevant memories
91
- - When users share important information, use the 'retain' tool to remember it
92
- - For complex questions requiring synthesis, use the 'reflect' tool
93
- - Always pass the user's ID as the bankId parameter
94
-
95
- Your memory persists across sessions!`,
96
- prompt: 'Remember that I am Alice and I love hiking',
97
- });
98
-
99
- for await (const chunk of result.textStream) {
100
- process.stdout.write(chunk);
101
- }
102
- ```
103
-
104
- ## API Reference
105
-
106
- ### `createHindsightTools(options)`
107
-
108
- Creates AI SDK tool definitions for Hindsight memory operations.
109
-
110
- **Parameters:**
111
-
112
- - `options.client`: `HindsightClient` - Hindsight client instance
113
- - `options.retainDescription`: `string` (optional) - Custom description for the retain tool
114
- - `options.recallDescription`: `string` (optional) - Custom description for the recall tool
115
- - `options.reflectDescription`: `string` (optional) - Custom description for the reflect tool
116
-
117
- **Returns:** Object with three tools: `retain`, `recall`, and `reflect`
118
-
119
- ### Tool: `retain`
120
-
121
- Store information in long-term memory.
122
-
123
- **Parameters:**
124
- - `bankId`: `string` - Memory bank ID (usually the user ID)
125
- - `content`: `string` - Content to store
126
- - `documentId`: `string` (optional) - Document ID for grouping/upserting
127
- - `timestamp`: `string` (optional) - ISO timestamp for when the memory occurred
128
- - `context`: `string` (optional) - Additional context about the memory
129
-
130
- **Returns:**
131
- ```typescript
132
- {
133
- success: boolean;
134
- itemsCount: number;
135
- }
136
- ```
137
-
138
- ### Tool: `recall`
139
-
140
- Search memory for relevant information.
141
-
142
- **Parameters:**
143
- - `bankId`: `string` - Memory bank ID
144
- - `query`: `string` - What to search for
145
- - `types`: `string[]` (optional) - Filter by fact types
146
- - `maxTokens`: `number` (optional) - Maximum tokens to return
147
- - `budget`: `'low' | 'mid' | 'high'` (optional) - Processing budget
148
- - `queryTimestamp`: `string` (optional) - Query from a specific time (ISO format)
149
- - `includeEntities`: `boolean` (optional) - Include entity observations
150
- - `includeChunks`: `boolean` (optional) - Include raw chunks
151
-
152
- **Returns:**
153
- ```typescript
154
- {
155
- results: Array<{
156
- id: string;
157
- text: string;
158
- type?: string;
159
- entities?: string[];
160
- context?: string;
161
- occurred_start?: string;
162
- occurred_end?: string;
163
- mentioned_at?: string;
164
- document_id?: string;
165
- metadata?: Record<string, string>;
166
- chunk_id?: string;
167
- }>;
168
- entities?: Record<string, EntityState>;
169
- }
170
- ```
171
-
172
- ### Tool: `reflect`
173
-
174
- Analyze memories to form insights and generate contextual answers.
175
-
176
- **Parameters:**
177
- - `bankId`: `string` - Memory bank ID
178
- - `query`: `string` - Question to reflect on
179
- - `context`: `string` (optional) - Additional context for reflection
180
- - `budget`: `'low' | 'mid' | 'high'` (optional) - Processing budget
181
-
182
- **Returns:**
183
- ```typescript
184
- {
185
- text: string;
186
- basedOn?: Array<{
187
- id?: string;
188
- text: string;
189
- type?: string;
190
- context?: string;
191
- occurred_start?: string;
192
- occurred_end?: string;
193
- }>;
194
- }
195
- ```
196
-
197
- ## Advanced Usage
198
-
199
- ### Custom Tool Descriptions
200
-
201
- Customize tool descriptions to guide model behavior:
202
-
203
- ```typescript
204
- const tools = createHindsightTools({
205
- client: hindsightClient,
206
- retainDescription: 'Store user preferences and important facts. Always include context.',
207
- recallDescription: 'Search past conversations. Use specific queries for best results.',
208
- reflectDescription: 'Synthesize insights from memories. Use for complex questions.',
209
- });
210
- ```
211
-
212
- ### Multi-User Scenarios
213
-
214
- Each tool call accepts a `bankId` parameter, making it easy to support multiple users:
215
-
216
- ```typescript
25
+ // 3. Use with AI SDK
217
26
  const result = await generateText({
218
27
  model: anthropic('claude-sonnet-4-20250514'),
219
28
  tools,
220
- prompt: `User ID: ${userId}\n\nRemember that I prefer dark mode`,
221
- });
222
- ```
223
-
224
- The model will automatically pass the user ID to the tools.
225
-
226
- ### Using with ToolLoopAgent
227
-
228
- ```typescript
229
- import { ToolLoopAgent, stopWhen, stepCountIs } from 'ai';
230
-
231
- const agent = new ToolLoopAgent({
232
- model: anthropic('claude-sonnet-4-20250514'),
233
- tools,
234
- instructions: `You are a personal assistant with long-term memory.
235
-
236
- Always check memory before responding using the recall tool.
237
- Store important user preferences with the retain tool.
238
- Use the reflect tool to analyze patterns in the user's behavior.`,
239
- stopWhen: stepCountIs(10),
29
+ system: `You have long-term memory. Use:
30
+ - 'recall' to search past conversations
31
+ - 'retain' to remember important information
32
+ - 'reflect' to synthesize insights from memories`,
33
+ prompt: 'Remember that Alice loves hiking and prefers spicy food',
240
34
  });
241
35
 
242
- const result = await agent.generate({
243
- prompt: 'What did I say I wanted to work on this week?',
244
- });
36
+ console.log(result.text);
245
37
  ```
246
38
 
247
- ## HTTP Client Example
248
-
249
- If you prefer not to install the full Hindsight client, you can use a simple HTTP client:
250
-
251
- ```typescript
252
- import type { HindsightClient } from '@vectorize-io/hindsight-ai-sdk';
39
+ ## Features
253
40
 
254
- const httpClient: HindsightClient = {
255
- async retain(bankId, content, options = {}) {
256
- const response = await fetch(`${HINDSIGHT_URL}/v1/default/banks/${bankId}/memories/retain`, {
257
- method: 'POST',
258
- headers: { 'Content-Type': 'application/json' },
259
- body: JSON.stringify({
260
- content,
261
- timestamp: options.timestamp,
262
- context: options.context,
263
- metadata: options.metadata,
264
- document_id: options.documentId,
265
- async: options.async,
266
- }),
267
- });
268
- return response.json();
269
- },
41
+ **Three Memory Tools**: `retain` (store), `recall` (retrieve), and `reflect` (reason over memories)
42
+ **AI SDK 6 Native**: Works with `generateText`, `streamText`, and `ToolLoopAgent`
43
+ **Multi-User Support**: Dynamic bank IDs per call for multi-user scenarios
44
+ **Type-Safe**: Full TypeScript support with Zod schemas
45
+ **Flexible Client**: Works with the official TypeScript client or custom HTTP clients
270
46
 
271
- async recall(bankId, query, options = {}) {
272
- const response = await fetch(`${HINDSIGHT_URL}/v1/default/banks/${bankId}/memories/recall`, {
273
- method: 'POST',
274
- headers: { 'Content-Type': 'application/json' },
275
- body: JSON.stringify({
276
- query,
277
- types: options.types,
278
- max_tokens: options.maxTokens,
279
- budget: options.budget,
280
- trace: options.trace,
281
- query_timestamp: options.queryTimestamp,
282
- include_entities: options.includeEntities,
283
- max_entity_tokens: options.maxEntityTokens,
284
- include_chunks: options.includeChunks,
285
- max_chunk_tokens: options.maxChunkTokens,
286
- }),
287
- });
288
- return response.json();
289
- },
47
+ ## Documentation
290
48
 
291
- async reflect(bankId, query, options = {}) {
292
- const response = await fetch(`${HINDSIGHT_URL}/v1/default/banks/${bankId}/reflect`, {
293
- method: 'POST',
294
- headers: { 'Content-Type': 'application/json' },
295
- body: JSON.stringify({
296
- query,
297
- context: options.context,
298
- budget: options.budget,
299
- }),
300
- });
301
- return response.json();
302
- },
303
- };
49
+ 📖 **[Full Documentation](https://vectorize.io/hindsight/sdks/integrations/ai-sdk)**
304
50
 
305
- const tools = createHindsightTools({ client: httpClient });
306
- ```
51
+ The complete documentation includes:
52
+ - Detailed tool descriptions and parameters
53
+ - Advanced usage patterns (streaming, multi-user, ToolLoopAgent)
54
+ - HTTP client example (no dependencies)
55
+ - TypeScript types and API reference
56
+ - Best practices and system prompt examples
307
57
 
308
58
  ## Running Hindsight Locally
309
59
 
310
- The easiest way to run Hindsight for development:
311
-
312
60
  ```bash
313
61
  # Install and run with embedded mode (no setup required)
314
62
  uvx hindsight-embed@latest -p myapp daemon start
@@ -316,41 +64,16 @@ uvx hindsight-embed@latest -p myapp daemon start
316
64
  # The API will be available at http://localhost:8000
317
65
  ```
318
66
 
319
- For production deployments, see the [Hindsight Documentation](https://vectorize.io/hindsight).
67
+ ## Examples
320
68
 
321
- ## TypeScript Types
69
+ Full examples are available in the [GitHub repository](https://github.com/vectorize-io/hindsight/tree/main/examples/ai-sdk).
322
70
 
323
- All types are exported for your convenience:
324
-
325
- ```typescript
326
- import type {
327
- Budget,
328
- HindsightClient,
329
- HindsightTools,
330
- HindsightToolsOptions,
331
- RecallResult,
332
- RecallResponse,
333
- ReflectFact,
334
- ReflectResponse,
335
- RetainResponse,
336
- EntityState,
337
- ChunkData,
338
- } from '@vectorize-io/hindsight-ai-sdk';
339
- ```
340
-
341
- ## Documentation & Resources
71
+ ## Support
342
72
 
343
- - [Hindsight Documentation](https://vectorize.io/hindsight)
344
- - [Vercel AI SDK Documentation](https://ai-sdk.dev)
345
- - [GitHub Repository](https://github.com/vectorize-io/hindsight)
346
- - [Examples](https://github.com/vectorize-io/hindsight/tree/main/examples)
73
+ - [Documentation](https://vectorize.io/hindsight)
74
+ - [GitHub Issues](https://github.com/vectorize-io/hindsight/issues)
75
+ - Email: support@vectorize.io
347
76
 
348
77
  ## License
349
78
 
350
79
  MIT
351
-
352
- ## Support
353
-
354
- For issues and questions:
355
- - [GitHub Issues](https://github.com/vectorize-io/hindsight/issues)
356
- - Email: support@vectorize.io
@@ -193,7 +193,6 @@ export interface HindsightClient {
193
193
  isActive?: boolean;
194
194
  tags?: string[];
195
195
  }): Promise<CreateDirectiveResponse>;
196
- getDirective(bankId: string, directiveId: string): Promise<DirectiveResponse | null>;
197
196
  listDirectives(bankId: string, options?: {
198
197
  tags?: string[];
199
198
  tagsMatch?: 'any' | 'all' | 'exact';
@@ -333,15 +332,5 @@ export declare function createHindsightTools({ client, retainDescription, recall
333
332
  tags: string[];
334
333
  createdAt: string;
335
334
  }>;
336
- getDirective: import("ai").Tool<{
337
- bankId: string;
338
- directiveId: string;
339
- }, {
340
- id: string;
341
- name: string;
342
- content: string;
343
- tags: string[];
344
- isActive: boolean;
345
- } | null>;
346
335
  };
347
336
  export type HindsightTools = ReturnType<typeof createHindsightTools>;
@@ -77,10 +77,6 @@ export function createHindsightTools({ client, retainDescription, recallDescript
77
77
  isActive: z.boolean().optional().describe('Whether this directive is active (default true)'),
78
78
  tags: z.array(z.string()).optional().describe('Tags for filtering'),
79
79
  });
80
- const getDirectiveParams = z.object({
81
- bankId: z.string().describe('Memory bank ID (usually the user ID)'),
82
- directiveId: z.string().describe('ID of the directive to retrieve'),
83
- });
84
80
  return {
85
81
  retain: tool({
86
82
  description: retainDescription ??
@@ -206,22 +202,5 @@ export function createHindsightTools({ client, retainDescription, recallDescript
206
202
  };
207
203
  },
208
204
  }),
209
- getDirective: tool({
210
- description: `Retrieve a directive by its ID. Returns the directive's content, tags, and active status.`,
211
- inputSchema: getDirectiveParams,
212
- execute: async (input) => {
213
- const result = await client.getDirective(input.bankId, input.directiveId);
214
- if (!result) {
215
- return null;
216
- }
217
- return {
218
- id: result.id,
219
- name: result.name,
220
- content: result.content,
221
- tags: result.tags,
222
- isActive: result.is_active,
223
- };
224
- },
225
- }),
226
205
  };
227
206
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vectorize-io/hindsight-ai-sdk",
3
- "version": "0.4.9",
3
+ "version": "0.4.10",
4
4
  "description": "Hindsight memory integration for Vercel AI SDK - Give your AI agents persistent, human-like memory",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",