doc: add go client examples (#380)

* doc: add go client examples

* doc: add go client examples
This commit is contained in:
Nicolò Boschi 2026-02-16 14:43:03 +01:00 committed by GitHub
parent 95c4220477
commit 5883e5af2d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 174 additions and 16 deletions

View file

@ -489,8 +489,10 @@ def convert_tags_to_structured(tags: list[str]) -> dict[str, str]:
- sdk: Package name (detected from tag values)
- topic: anything else (Learning, Quick Start, etc.)
If sdk tag starts with '@vectorize-io', it's Node.js.
Otherwise assumes Python.
Supported languages:
- Node.js: packages starting with '@vectorize-io'
- Go: packages ending with '-go' or containing 'go-'
- Python: everything else
"""
structured = {}
topic_tags = {"Learning", "Quick Start", "Recommendation", "Chat"}

View file

@ -0,0 +1,102 @@
---
sidebar_position: 3
---
# Go Memory-Augmented API
:::info Complete Application
This is a complete, runnable application demonstrating Hindsight integration.
[**View source on GitHub →**](https://github.com/vectorize-io/hindsight-cookbook/tree/main/applications/go-memory-service)
:::
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.
## Features
- 🔐 **Per-User Isolation**: Each user gets their own memory bank
- 🧠 **Context-Aware Responses**: Uses recall + reflect for personalized answers
- 🏃 **Fire-and-Forget Memory**: Background goroutines store interactions without blocking responses
- 🏷️ **Tag-Based Partitioning**: Organize memories by type (projects, debugging, preferences)
## Setup
### 1. Start Hindsight
```bash
export OPENAI_API_KEY=your-key
docker run --rm -it --pull always -p 8888:8888 -p 9999:9999 \
-e HINDSIGHT_API_LLM_API_KEY=$OPENAI_API_KEY \
-e HINDSIGHT_API_LLM_MODEL=o3-mini \
-v $HOME/.hindsight-docker:/home/hindsight/.pg0 \
ghcr.io/vectorize-io/hindsight:latest
```
### 2. Run the service
```bash
go run main.go
```
### 3. Try it out
```bash
# Store memories
curl -s localhost:8080/learn -d '{
"user_id": "alice",
"content": "I am building a Go microservice with gRPC and PostgreSQL",
"tags": ["project"]
}'
curl -s localhost:8080/learn -d '{
"user_id": "alice",
"content": "I prefer structured logging with slog over zerolog",
"tags": ["preferences"]
}'
# Ask questions (uses recall + reflect)
curl -s localhost:8080/ask -d '{
"user_id": "alice",
"query": "What tech stack am I using?"
}' | jq .
# Raw memory recall
curl -s "localhost:8080/recall/alice?q=database" | jq .
```
## API Endpoints
- `POST /learn` - Store new information for a user
- `POST /ask` - Ask a question using the user's memories
- `GET /recall/{userID}?q=query` - Direct memory recall
- `GET /health` - Health check
## Key Patterns
**Per-User Banks**: Each user gets an isolated memory bank (`user-alice`, `user-bob`)
**Async Memory Storage**: Interactions are stored in background goroutines:
```go
go func() {
bgCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
retainReq := hindsight.RetainRequest{
Items: []hindsight.MemoryItem{{
Content: interaction,
Context: *hindsight.NewNullableString(hindsight.PtrString("Q&A interaction")),
}},
}
client.MemoryAPI.RetainMemories(bgCtx, bankID).RetainRequest(retainReq).Execute()
}()
```
**Tag-Based Filtering**: Partition memories within a bank by type for scoped retrieval
## Learn More
- [Go SDK Documentation](https://hindsight.vectorize.io/sdks/go)
- [Hindsight Documentation](https://hindsight.vectorize.io)

View file

@ -1,5 +1,5 @@
---
sidebar_position: 3
sidebar_position: 4
---
# Memory Approaches Comparison Demo

View file

@ -1,5 +1,5 @@
---
sidebar_position: 4
sidebar_position: 5
---
# Tool Learning Demo

View file

@ -1,5 +1,5 @@
---
sidebar_position: 5
sidebar_position: 6
---
# OpenAI Agent + Hindsight Memory Integration

View file

@ -1,5 +1,5 @@
---
sidebar_position: 6
sidebar_position: 7
---
# Sanity CMS Blog Memory

View file

@ -1,5 +1,5 @@
---
sidebar_position: 7
sidebar_position: 8
---
# Stance Tracker

View file

@ -1,5 +1,5 @@
---
sidebar_position: 8
sidebar_position: 9
---
# Hindsight AI SDK - Personal Chef

View file

@ -105,6 +105,12 @@ Learn how to build with Hindsight through practical examples:
description: "Delivery agent simulation demonstrating learning through mental models",
tags: { sdk: "hindsight-client", topic: "Learning" }
},
{
title: "Go Memory-Augmented API",
href: "/cookbook/applications/go-memory-service",
description: "Go HTTP microservice with per-user memory banks for a developer knowledge assistant",
tags: { sdk: "hindsight-go", topic: "Learning" }
},
{
title: "Memory Approaches Comparison Demo",
href: "/cookbook/applications/hindsight-litellm-demo",

View file

@ -50,7 +50,7 @@ const apiClient = createClient(createConfig({ baseUrl: 'http://localhost:8888' }
// Get document to expand context from recall results
const { data: doc, error } = await sdk.getDocument({
client: apiClient,
path: { bank_id: 'my-bank', document_id: 'meeting-2024-03-15' }
path: { bank_id: 'my-bank', document_id: 'meeting-2024-03-15-section-1' }
});
if (error) {
@ -68,7 +68,7 @@ console.log(`Created: ${doc.created_at}`);
// Delete document and all its memories
const { data: deleteResult } = await sdk.deleteDocument({
client: apiClient,
path: { bank_id: 'my-bank', document_id: 'meeting-2024-03-15' }
path: { bank_id: 'my-bank', document_id: 'meeting-2024-03-15-section-1' }
});
console.log(`Deleted ${deleteResult.memory_units_deleted} memories`);

View file

@ -90,10 +90,9 @@ client.retain_batch(
client.retain_batch(
bank_id="my-bank",
items=[
{"content": "Alice mentioned she prefers dark mode"},
{"content": "Bob asked about keyboard shortcuts"}
{"content": "Alice mentioned she prefers dark mode", "document_id": "support_session_123_msg_1"},
{"content": "Bob asked about keyboard shortcuts", "document_id": "support_session_123_msg_2"}
],
document_id="support_session_123",
document_tags=["session:123", "support"] # Applied to all items
)
# [/docs:retain-with-document-tags]

View file

@ -165,6 +165,14 @@ const sidebars: SidebarsConfig = {
id: 'sdks/nodejs',
label: 'Node.js',
},
{
type: 'doc',
id: 'sdks/go',
label: 'Go',
customProps: {
icon: "/img/icons/golang.png"
}
},
{
type: 'doc',
id: 'sdks/cli',

View file

@ -17,11 +17,12 @@ interface RecipeCarouselProps {
items: RecipeCard[];
}
// Language icons using inline SVG data URIs
// Language icons using inline SVG data URIs or image paths
const LANGUAGE_ICONS: Record<string, string> = {
Python: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%233776ab' d='M14.25.18l.9.2.73.26.59.3.45.32.34.34.25.34.16.33.1.3.04.26.02.2-.01.13V8.5l-.05.63-.13.55-.21.46-.26.38-.3.31-.33.25-.35.19-.35.14-.33.1-.3.07-.26.04-.21.02H8.77l-.69.05-.59.14-.5.22-.41.27-.33.32-.27.35-.2.36-.15.37-.1.35-.07.32-.04.27-.02.21v3.06H3.17l-.21-.03-.28-.07-.32-.12-.35-.18-.36-.26-.36-.36-.35-.46-.32-.59-.28-.73-.21-.88-.14-1.05-.05-1.23.06-1.22.16-1.04.24-.87.32-.71.36-.57.4-.44.42-.33.42-.24.4-.16.36-.1.32-.05.24-.01h.16l.06.01h8.16v-.83H6.18l-.01-2.75-.02-.37.05-.34.11-.31.17-.28.25-.26.31-.23.38-.2.44-.18.51-.15.58-.12.64-.1.71-.06.77-.04.84-.02 1.27.05zm-6.3 1.98l-.23.33-.08.41.08.41.23.34.33.22.41.09.41-.09.33-.22.23-.34.08-.41-.08-.41-.23-.33-.33-.22-.41-.09-.41.09zm13.09 3.95l.28.06.32.12.35.18.36.27.36.35.35.47.32.59.28.73.21.88.14 1.04.05 1.23-.06 1.23-.16 1.04-.24.86-.32.71-.36.57-.4.45-.42.33-.42.24-.4.16-.36.09-.32.05-.24.02-.16-.01h-8.22v.82h5.84l.01 2.76.02.36-.05.34-.11.31-.17.29-.25.25-.31.24-.38.2-.44.17-.51.15-.58.13-.64.09-.71.07-.77.04-.84.01-1.27-.04-1.07-.14-.9-.2-.73-.25-.59-.3-.45-.33-.34-.34-.25-.34-.16-.33-.1-.3-.04-.25-.02-.2.01-.13v-5.34l.05-.64.13-.54.21-.46.26-.38.3-.32.33-.24.35-.2.35-.14.33-.1.3-.06.26-.04.21-.02.13-.01h5.84l.69-.05.59-.14.5-.21.41-.28.33-.32.27-.35.2-.36.15-.36.1-.35.07-.32.04-.28.02-.21V6.07h2.09l.14.01zm-6.47 14.25l-.23.33-.08.41.08.41.23.33.33.23.41.08.41-.08.33-.23.23-.33.08-.41-.08-.41-.23-.33-.33-.23-.41-.08-.41.08z'/%3E%3C/svg%3E",
'Node.js': "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23339933' d='M11.998 0c-.27 0-.54.07-.772.202L2.428 5.05C1.983 5.321 1.7 5.802 1.7 6.32v11.36c0 .518.283 1 .728 1.27l2.375 1.371c.64.321 1.094.32 1.468.32 1.203 0 1.89-.73 1.89-1.996V7.362c0-.146-.117-.264-.262-.264H7.11c-.146 0-.263.118-.263.264v11.283c0 .876-.906 1.753-2.38 1.01L2.103 18.28c-.046-.026-.073-.08-.073-.132V6.754c0-.051.027-.106.073-.132l8.798-5.08c.044-.026.102-.026.145 0l8.798 5.08c.046.026.074.081.074.132v11.394c0 .051-.028.106-.074.132l-8.798 5.08c-.043.026-.101.026-.144 0l-2.248-1.336c-.064-.037-.144-.04-.21-.011-.55.307-.658.373-1.177.45-.12.019-.301.06.073.276l2.93 1.738c.23.133.49.202.772.202s.542-.069.772-.202l8.798-5.08c.476-.27.772-.772.772-1.27V6.32c0-.518-.296-.999-.772-1.27L12.77.202C12.538.07 12.268 0 11.998 0zm2.657 6.343c-2.432 0-2.945.953-2.945 2.146 0 .145.117.263.263.263h.788c.131 0 .24-.095.261-.221.177-.718.708-1.08 1.633-1.08.738 0 1.177.168 1.177.803 0 .325-.128.567-.678.73l-1.69.419c-.899.223-1.47.756-1.47 1.636 0 1.076.905 1.715 2.423 1.715 1.704 0 2.55-.593 2.656-1.866.006-.073-.018-.144-.066-.197-.047-.053-.114-.083-.186-.083h-.791c-.123 0-.23.089-.258.207-.286.644-.98.849-1.817.849-.65 0-1.16-.207-1.16-.725 0-.325.144-.424.903-.609l1.476-.367c.898-.223 1.462-.72 1.462-1.613 0-1.12-.937-1.787-2.574-1.787z'/%3E%3C/svg%3E",
TypeScript: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%233178c6' d='M1.125 0C.502 0 0 .502 0 1.125v21.75C0 23.498.502 24 1.125 24h21.75c.623 0 1.125-.502 1.125-1.125V1.125C24 .502 23.498 0 22.875 0zm17.363 9.75c.612 0 1.154.037 1.627.111.472.074.914.187 1.323.34v2.458c-.444-.223-.935-.39-1.473-.501-.539-.111-1.09-.167-1.655-.167-.562 0-1.011.062-1.349.187-.338.124-.507.335-.507.632 0 .234.095.42.285.558.19.138.503.275.94.411l1.503.434c.915.262 1.577.609 1.984 1.04.408.432.612.998.612 1.699 0 .915-.35 1.638-1.05 2.168-.7.53-1.667.795-2.9.795-.591 0-1.178-.051-1.76-.153-.582-.102-1.13-.258-1.645-.468v-2.503c.544.287 1.09.507 1.637.66.546.153 1.084.23 1.613.23.609 0 1.071-.073 1.386-.219.315-.146.472-.369.472-.669 0-.262-.106-.471-.318-.628-.212-.157-.551-.306-1.017-.447l-1.42-.395c-.877-.234-1.515-.563-1.916-.985-.4-.422-.6-.98-.6-1.673 0-.857.348-1.545 1.044-2.063.696-.518 1.633-.777 2.811-.777zm-13.6 1.77H8.45l-.031 4.18c0 .754-.13 1.314-.39 1.68-.26.367-.65.55-1.168.55-.286 0-.56-.037-.822-.11-.262-.074-.506-.173-.733-.297v1.818c.319.111.665.187 1.038.228.373.04.736.06 1.089.06.924 0 1.623-.247 2.097-.74.474-.494.711-1.254.711-2.28V11.52z'/%3E%3C/svg%3E",
Go: "/img/icons/golang.png",
};
// Get language icon based on package name
@ -30,6 +31,10 @@ function getPackageIcon(packageName: string): string | undefined {
if (packageName.startsWith('@vectorize-io')) {
return LANGUAGE_ICONS['Node.js'];
}
// If it ends with -go or contains go-, it's Go
if (packageName.endsWith('-go') || packageName.includes('go-')) {
return LANGUAGE_ICONS.Go;
}
// Otherwise assume Python
return LANGUAGE_ICONS.Python;
}

View file

@ -639,8 +639,8 @@ article p {
line-height: 1.7;
}
/* Links with gradient */
article a:not(.button):not([class*="hash-link"]) {
/* Links with gradient - exclude RecipeCarousel cards and sidebar links */
article a:not(.button):not([class*="hash-link"]):not([class*="card"]):not([class*="menu__link"]) {
background: var(--hindsight-gradient);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;

View file

@ -0,0 +1,36 @@
import React from 'react';
import Link from '@theme-original/DocSidebarItem/Link';
import type LinkType from '@theme/DocSidebarItem/Link';
import type {WrapperProps} from '@docusaurus/types';
type Props = WrapperProps<typeof LinkType>;
export default function LinkWrapper(props: Props): JSX.Element {
const {item} = props;
const icon = item.customProps?.icon as string | undefined;
if (!icon) {
return <Link {...props} />;
}
// Create a modified item with icon in the label
const modifiedItem = {
...item,
label: (
<span style={{display: 'flex', alignItems: 'center', gap: '8px'}}>
<img
src={icon}
alt=""
style={{
width: '16px',
height: '16px',
flexShrink: 0
}}
/>
<span>{item.label}</span>
</span>
),
};
return <Link {...props} item={modifiedItem} />;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB