Skip to content

Commit 90ad003

Browse files
authored
docs: add AI SDK integration documentation (#304)
* docs: add AI SDK integration documentation - Add comprehensive AI SDK documentation in docs/sdks/integrations/ai-sdk.md - Detailed description of all three memory tools (retain, recall, reflect) - Complete parameter documentation and return types - Advanced usage patterns (streaming, multi-user, ToolLoopAgent) - HTTP client example for zero-dependency usage - TypeScript types and API reference - Best practices and system prompt examples - Update AI SDK README to brief quickstart with link to docs - Single source of truth: comprehensive docs in documentation site - README now focuses on quick setup and points to full docs - Maintains features list and basic example for npm page * fix
1 parent 278718d commit 90ad003

26 files changed

Lines changed: 2188 additions & 702 deletions

File tree

hindsight-dev/hindsight_dev/sync_cookbook.py

Lines changed: 346 additions & 82 deletions
Large diffs are not rendered by default.
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
---
2+
sidebar_position: 8
3+
---
4+
5+
# Hindsight AI SDK - Personal Chef
6+
7+
8+
:::info Complete Application
9+
This is a complete, runnable application demonstrating Hindsight integration.
10+
[**View source on GitHub →**](https://github.com/vectorize-io/hindsight-cookbook/tree/main/applications/taste-ai)
11+
:::
12+
13+
14+
A personal food assistant demonstrating three key Hindsight integrations using the [Vercel AI SDK v6](https://sdk.vercel.ai/docs).
15+
16+
## Architecture: Single Bank with User Tags
17+
18+
This demo uses a **single Hindsight bank** (`taste-ai`) for all users, with each user's data tagged using `user:${username}`.
19+
20+
```typescript
21+
// All users share the same bank
22+
const BANK_ID = 'taste-ai';
23+
24+
// Each memory is tagged with the user
25+
await hindsightTools.retain.execute({
26+
bankId: BANK_ID,
27+
content: userData,
28+
tags: [`user:${username}`],
29+
});
30+
```
31+
32+
This architecture enables:
33+
- **Per-user queries**: Filter by `user:alice` to get personalized results
34+
- **Aggregated insights**: Query across all users to find popular recipes or common dietary patterns
35+
- **Simplified management**: One bank to maintain instead of per-user banks
36+
37+
## Three Hindsight Integrations
38+
39+
### 1. Meal Suggestions with Memory Recall & Reflection
40+
41+
Uses `recall` and `reflect` tools with AI SDK's agent-based approach to gather personalized context.
42+
43+
```typescript
44+
const contextResult = await generateText({
45+
model: llmModel,
46+
tools: {
47+
recall: hindsightTools.recall,
48+
reflect: hindsightTools.reflect,
49+
},
50+
toolChoice: 'auto',
51+
prompt: `You are gathering context for personalized ${mealType} recipe suggestions.
52+
53+
Use the recall tool to search for the user's food preferences, dislikes, and recent meals.
54+
Then use the reflect tool to analyze their dietary patterns and restrictions.
55+
56+
After gathering context, summarize their preferences and recent eating patterns.`,
57+
});
58+
```
59+
60+
The AI agent autonomously:
61+
- Searches memory for cuisine preferences and dietary restrictions
62+
- Analyzes recent protein consumption for variety
63+
- Identifies foods to avoid
64+
65+
### 2. Goal Progress Tracking with Mental Models
66+
67+
Uses mental models to automatically maintain updated insights about user progress.
68+
69+
```typescript
70+
// Create a mental model that auto-refreshes after new meals
71+
await hindsightTools.createMentalModel.execute({
72+
bankId: BANK_ID,
73+
mentalModelId: getMentalModelId(username, 'goals'),
74+
name: `${username}'s Goal Progress`,
75+
sourceQuery: `Analyze ${username}'s dietary goals and eating patterns.
76+
Describe their progress towards their stated goals (weight loss, muscle gain, etc.).`,
77+
tags: [`user:${username}`],
78+
autoRefresh: true, // Refreshes automatically after consolidation
79+
});
80+
81+
// Query the mental model for current insights
82+
const result = await hindsightTools.queryMentalModel.execute({
83+
bankId: BANK_ID,
84+
mentalModelId: mentalModelId,
85+
});
86+
```
87+
88+
Mental models automatically:
89+
- Track progress towards dietary goals
90+
- Update after each new meal is logged
91+
- Provide fresh insights without manual refresh
92+
93+
### 3. Language Enforcement with Directives
94+
95+
Uses directives to ensure all responses match user's language preference.
96+
97+
```typescript
98+
await hindsightClient.createDirective(BANK_ID, {
99+
name: `${username}'s Language Preference`,
100+
content: `Always respond in ${language}. All suggestions must be in ${language}.`,
101+
priority: 100,
102+
tags: [`user:${username}`, 'directive:language'],
103+
});
104+
```
105+
106+
Directives are automatically injected when mental models generate insights, ensuring consistent language across all interactions.
107+
108+
## Running the Demo
109+
110+
```bash
111+
npm install
112+
npm run dev
113+
```
114+
115+
**Requirements:**
116+
- Hindsight server running at `http://localhost:8888` (or set `HINDSIGHT_URL`)
117+
- Node.js 18+
118+
119+
## Learn More
120+
121+
- [Hindsight AI SDK on npm](https://www.npmjs.com/package/@vectorize-io/hindsight-ai-sdk)
122+
- [AI SDK Documentation](https://sdk.vercel.ai/docs)
Lines changed: 127 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,147 @@
11
---
22
sidebar_position: 1
3+
hide_table_of_contents: true
4+
pagination_next: null
5+
pagination_prev: null
6+
custom_edit_url: null
7+
sidebar_class_name: hidden-sidebar
38
---
49

510
import RecipeCarousel from '@site/src/components/RecipeCarousel';
611

12+
<div className="cookbook-page">
13+
714
# Cookbook
815

9-
Practical patterns, recipes, and complete applications for building with Hindsight.
16+
Learn how to build with Hindsight through practical examples:
17+
18+
- **[Recipes](#recipes)** - Step-by-step guides and patterns for common use cases
19+
- **[Applications](#applications)** - Complete, runnable applications demonstrating Hindsight integration
1020

1121
<RecipeCarousel
1222
title="Recipes"
1323
items={[
14-
{ title: "Hindsight Quickstart", href: "/cookbook/recipes/quickstart" },
15-
{ title: "Per-User Memory", href: "/cookbook/recipes/per-user-memory" },
16-
{ title: "Support Agent with Shared Knowledge", href: "/cookbook/recipes/support-agent-shared-knowledge" },
17-
{ title: "Memory with LiteLLM", href: "/cookbook/recipes/litellm-memory-demo" },
18-
{ title: "Routing Tool Learning", href: "/cookbook/recipes/tool-learning-demo" },
19-
{ title: "Fitness Coach with Hindsight Memory", href: "/cookbook/recipes/fitness_tracker" },
20-
{ title: "Healthcare Assistant with Hindsight Memory", href: "/cookbook/recipes/healthcare_assistant" },
21-
{ title: "Movie Recommendation Assistant with Hindsight Memory", href: "/cookbook/recipes/movie_recommendation" },
22-
{ title: "Personal AI Assistant with Hindsight Memory", href: "/cookbook/recipes/personal_assistant" },
23-
{ title: "Personalized Search Agent with Hindsight Memory", href: "/cookbook/recipes/personalized_search" },
24-
{ title: "Study Buddy with Hindsight Memory", href: "/cookbook/recipes/study_buddy" }
24+
{
25+
title: "Hindsight Quickstart",
26+
href: "/cookbook/recipes/quickstart",
27+
description: "Learn the basics: retain, recall, and reflect",
28+
tags: { sdk: "hindsight-client", topic: "Quick Start" }
29+
},
30+
{
31+
title: "Per-User Memory",
32+
href: "/cookbook/recipes/per-user-memory",
33+
description: "Build a chatbot with per-user memory isolation",
34+
tags: { sdk: "hindsight-client", topic: "Learning" }
35+
},
36+
{
37+
title: "Support Agent with Shared Knowledge",
38+
href: "/cookbook/recipes/support-agent-shared-knowledge",
39+
description: "Combine per-user memory with shared product documentation",
40+
tags: { sdk: "hindsight-client", topic: "Learning" }
41+
},
42+
{
43+
title: "Memory with LiteLLM",
44+
href: "/cookbook/recipes/litellm-memory-demo",
45+
description: "Add automatic memory to any LLM app using LiteLLM callbacks",
46+
tags: { sdk: "hindsight-litellm", topic: "Quick Start" }
47+
},
48+
{
49+
title: "Routing Tool Learning",
50+
href: "/cookbook/recipes/tool-learning-demo",
51+
description: "Teach an LLM which tool to use through feedback and memory",
52+
tags: { sdk: "hindsight-litellm", topic: "Learning" }
53+
},
54+
{
55+
title: "Fitness Coach with Hindsight Memory",
56+
href: "/cookbook/recipes/fitness_tracker",
57+
description: "Track workouts, diet, and progress with a personalized fitness coach",
58+
tags: { sdk: "hindsight-client", topic: "Recommendation" }
59+
},
60+
{
61+
title: "Healthcare Assistant with Hindsight Memory",
62+
href: "/cookbook/recipes/healthcare_assistant",
63+
description: "A supportive chatbot that remembers patient history and preferences",
64+
tags: { sdk: "hindsight-client", topic: "Recommendation" }
65+
},
66+
{
67+
title: "Movie Recommendation Assistant with Hindsight Memory",
68+
href: "/cookbook/recipes/movie_recommendation",
69+
description: "Get personalized movie recommendations that improve over time",
70+
tags: { sdk: "hindsight-client", topic: "Recommendation" }
71+
},
72+
{
73+
title: "Personal AI Assistant with Hindsight Memory",
74+
href: "/cookbook/recipes/personal_assistant",
75+
description: "A general-purpose assistant that remembers your life and preferences",
76+
tags: { sdk: "hindsight-client", topic: "Recommendation" }
77+
},
78+
{
79+
title: "Personalized Search Agent with Hindsight Memory",
80+
href: "/cookbook/recipes/personalized_search",
81+
description: "Search assistant that learns your location, diet, and lifestyle",
82+
tags: { sdk: "hindsight-client", topic: "Recommendation" }
83+
},
84+
{
85+
title: "Study Buddy with Hindsight Memory",
86+
href: "/cookbook/recipes/study_buddy",
87+
description: "Track study sessions, identify knowledge gaps, and get personalized review suggestions",
88+
tags: { sdk: "hindsight-client", topic: "Learning" }
89+
}
2590
]}
2691
/>
2792

2893
<RecipeCarousel
2994
title="Applications"
3095
items={[
31-
{ title: "Chat Memory App", href: "/cookbook/applications/chat-memory" },
32-
{ title: "Deliveryman Demo", href: "/cookbook/applications/deliveryman-demo" },
33-
{ title: "Memory Approaches Comparison Demo", href: "/cookbook/applications/hindsight-litellm-demo" },
34-
{ title: "Tool Learning Demo", href: "/cookbook/applications/hindsight-tool-learning-demo" },
35-
{ title: "OpenAI Agent + Hindsight Memory Integration", href: "/cookbook/applications/openai-fitness-coach" },
36-
{ title: "Sanity CMS Blog Memory", href: "/cookbook/applications/sanity-blog-memory" },
37-
{ title: "Stance Tracker", href: "/cookbook/applications/stancetracker" }
96+
{
97+
title: "Chat Memory App",
98+
href: "/cookbook/applications/chat-memory",
99+
description: "Real-time chat app with per-user memory using Groq and Hindsight",
100+
tags: { sdk: "hindsight-client", topic: "Chat" }
101+
},
102+
{
103+
title: "Deliveryman Demo",
104+
href: "/cookbook/applications/deliveryman-demo",
105+
description: "Delivery agent simulation demonstrating learning through mental models",
106+
tags: { sdk: "hindsight-client", topic: "Learning" }
107+
},
108+
{
109+
title: "Memory Approaches Comparison Demo",
110+
href: "/cookbook/applications/hindsight-litellm-demo",
111+
description: "Interactive comparison of memory approaches: none, full history, and semantic retrieval",
112+
tags: { sdk: "hindsight-litellm", topic: "Quick Start" }
113+
},
114+
{
115+
title: "Tool Learning Demo",
116+
href: "/cookbook/applications/hindsight-tool-learning-demo",
117+
description: "Show how Hindsight helps LLMs learn which tool to use when names are ambiguous",
118+
tags: { sdk: "hindsight-litellm", topic: "Learning" }
119+
},
120+
{
121+
title: "OpenAI Agent + Hindsight Memory Integration",
122+
href: "/cookbook/applications/openai-fitness-coach",
123+
description: "Fitness coach using OpenAI Assistants with Hindsight as memory backend",
124+
tags: { sdk: "hindsight-client", topic: "Recommendation" }
125+
},
126+
{
127+
title: "Sanity CMS Blog Memory",
128+
href: "/cookbook/applications/sanity-blog-memory",
129+
description: "Sync Sanity CMS blog posts to Hindsight for semantic search and AI insights",
130+
tags: { sdk: "hindsight-client", topic: "Learning" }
131+
},
132+
{
133+
title: "Stance Tracker",
134+
href: "/cookbook/applications/stancetracker",
135+
description: "Track political candidates' stances over time with automated web scraping",
136+
tags: { sdk: "hindsight-client", topic: "Recommendation" }
137+
},
138+
{
139+
title: "Hindsight AI SDK - Personal Chef",
140+
href: "/cookbook/applications/taste-ai",
141+
description: "Personal food assistant with AI SDK v6 showcasing recall, mental models, and directives",
142+
tags: { sdk: "@vectorize-io/hindsight-ai-sdk", topic: "Recommendation" }
143+
}
38144
]}
39145
/>
146+
147+
</div>

0 commit comments

Comments
 (0)