Skip to content

Commit 5883e5a

Browse files
authored
doc: add go client examples (#380)
* doc: add go client examples * doc: add go client examples
1 parent 95c4220 commit 5883e5a

16 files changed

Lines changed: 174 additions & 16 deletions

File tree

hindsight-dev/hindsight_dev/sync_cookbook.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,10 @@ def convert_tags_to_structured(tags: list[str]) -> dict[str, str]:
489489
- sdk: Package name (detected from tag values)
490490
- topic: anything else (Learning, Quick Start, etc.)
491491
492-
If sdk tag starts with '@vectorize-io', it's Node.js.
493-
Otherwise assumes Python.
492+
Supported languages:
493+
- Node.js: packages starting with '@vectorize-io'
494+
- Go: packages ending with '-go' or containing 'go-'
495+
- Python: everything else
494496
"""
495497
structured = {}
496498
topic_tags = {"Learning", "Quick Start", "Recommendation", "Chat"}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
sidebar_position: 3
3+
---
4+
5+
# Go Memory-Augmented API
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/go-memory-service)
11+
:::
12+
13+
14+
A Go HTTP microservice demonstrating per-user memory isolation with Hindsight. Remembers each user's tech stack, problems solved, and preferences to provide personalized assistance.
15+
16+
## Features
17+
18+
- 🔐 **Per-User Isolation**: Each user gets their own memory bank
19+
- 🧠 **Context-Aware Responses**: Uses recall + reflect for personalized answers
20+
- 🏃 **Fire-and-Forget Memory**: Background goroutines store interactions without blocking responses
21+
- 🏷️ **Tag-Based Partitioning**: Organize memories by type (projects, debugging, preferences)
22+
23+
## Setup
24+
25+
### 1. Start Hindsight
26+
27+
```bash
28+
export OPENAI_API_KEY=your-key
29+
30+
docker run --rm -it --pull always -p 8888:8888 -p 9999:9999 \
31+
-e HINDSIGHT_API_LLM_API_KEY=$OPENAI_API_KEY \
32+
-e HINDSIGHT_API_LLM_MODEL=o3-mini \
33+
-v $HOME/.hindsight-docker:/home/hindsight/.pg0 \
34+
ghcr.io/vectorize-io/hindsight:latest
35+
```
36+
37+
### 2. Run the service
38+
39+
```bash
40+
go run main.go
41+
```
42+
43+
### 3. Try it out
44+
45+
```bash
46+
# Store memories
47+
curl -s localhost:8080/learn -d '{
48+
"user_id": "alice",
49+
"content": "I am building a Go microservice with gRPC and PostgreSQL",
50+
"tags": ["project"]
51+
}'
52+
53+
curl -s localhost:8080/learn -d '{
54+
"user_id": "alice",
55+
"content": "I prefer structured logging with slog over zerolog",
56+
"tags": ["preferences"]
57+
}'
58+
59+
# Ask questions (uses recall + reflect)
60+
curl -s localhost:8080/ask -d '{
61+
"user_id": "alice",
62+
"query": "What tech stack am I using?"
63+
}' | jq .
64+
65+
# Raw memory recall
66+
curl -s "localhost:8080/recall/alice?q=database" | jq .
67+
```
68+
69+
## API Endpoints
70+
71+
- `POST /learn` - Store new information for a user
72+
- `POST /ask` - Ask a question using the user's memories
73+
- `GET /recall/{userID}?q=query` - Direct memory recall
74+
- `GET /health` - Health check
75+
76+
## Key Patterns
77+
78+
**Per-User Banks**: Each user gets an isolated memory bank (`user-alice`, `user-bob`)
79+
80+
**Async Memory Storage**: Interactions are stored in background goroutines:
81+
82+
```go
83+
go func() {
84+
bgCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
85+
defer cancel()
86+
87+
retainReq := hindsight.RetainRequest{
88+
Items: []hindsight.MemoryItem{{
89+
Content: interaction,
90+
Context: *hindsight.NewNullableString(hindsight.PtrString("Q&A interaction")),
91+
}},
92+
}
93+
client.MemoryAPI.RetainMemories(bgCtx, bankID).RetainRequest(retainReq).Execute()
94+
}()
95+
```
96+
97+
**Tag-Based Filtering**: Partition memories within a bank by type for scoped retrieval
98+
99+
## Learn More
100+
101+
- [Go SDK Documentation](https://hindsight.vectorize.io/sdks/go)
102+
- [Hindsight Documentation](https://hindsight.vectorize.io)

hindsight-docs/docs/cookbook/applications/hindsight-litellm-demo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 3
2+
sidebar_position: 4
33
---
44

55
# Memory Approaches Comparison Demo

hindsight-docs/docs/cookbook/applications/hindsight-tool-learning-demo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 4
2+
sidebar_position: 5
33
---
44

55
# Tool Learning Demo

hindsight-docs/docs/cookbook/applications/openai-fitness-coach.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 5
2+
sidebar_position: 6
33
---
44

55
# OpenAI Agent + Hindsight Memory Integration

hindsight-docs/docs/cookbook/applications/sanity-blog-memory.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 6
2+
sidebar_position: 7
33
---
44

55
# Sanity CMS Blog Memory

hindsight-docs/docs/cookbook/applications/stancetracker.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 7
2+
sidebar_position: 8
33
---
44

55
# Stance Tracker

hindsight-docs/docs/cookbook/applications/taste-ai.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 8
2+
sidebar_position: 9
33
---
44

55
# Hindsight AI SDK - Personal Chef

hindsight-docs/docs/cookbook/index.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ Learn how to build with Hindsight through practical examples:
105105
description: "Delivery agent simulation demonstrating learning through mental models",
106106
tags: { sdk: "hindsight-client", topic: "Learning" }
107107
},
108+
{
109+
title: "Go Memory-Augmented API",
110+
href: "/cookbook/applications/go-memory-service",
111+
description: "Go HTTP microservice with per-user memory banks for a developer knowledge assistant",
112+
tags: { sdk: "hindsight-go", topic: "Learning" }
113+
},
108114
{
109115
title: "Memory Approaches Comparison Demo",
110116
href: "/cookbook/applications/hindsight-litellm-demo",

hindsight-docs/examples/api/documents.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const apiClient = createClient(createConfig({ baseUrl: 'http://localhost:8888' }
5050
// Get document to expand context from recall results
5151
const { data: doc, error } = await sdk.getDocument({
5252
client: apiClient,
53-
path: { bank_id: 'my-bank', document_id: 'meeting-2024-03-15' }
53+
path: { bank_id: 'my-bank', document_id: 'meeting-2024-03-15-section-1' }
5454
});
5555

5656
if (error) {
@@ -68,7 +68,7 @@ console.log(`Created: ${doc.created_at}`);
6868
// Delete document and all its memories
6969
const { data: deleteResult } = await sdk.deleteDocument({
7070
client: apiClient,
71-
path: { bank_id: 'my-bank', document_id: 'meeting-2024-03-15' }
71+
path: { bank_id: 'my-bank', document_id: 'meeting-2024-03-15-section-1' }
7272
});
7373

7474
console.log(`Deleted ${deleteResult.memory_units_deleted} memories`);

0 commit comments

Comments
 (0)