Skip to content

Instantly share code, notes, and snippets.

@iamarcel
Last active June 27, 2025 08:08
Show Gist options
  • Save iamarcel/0da3e9c1179e9635caacb9dd84037a58 to your computer and use it in GitHub Desktop.
Save iamarcel/0da3e9c1179e9635caacb9dd84037a58 to your computer and use it in GitHub Desktop.
Example: Ingesting documents into your Petals memory
// Using the SDK, run npm install @marcelsamyn/memory first
import { MemoryClient } from "@marcelsamyn/memory/sdk";
const memory = new MemoryClient({
baseUrl: "https://petals.chat/api/memory",
apiKey: "your-petals-api-key-here"
});
await memory.ingestDocument({
document: {
id: "abc",
content: "Hello, world!",
timestamp: new Date()
},
userId: "user-123", // handled by Petals
updateExisting: true // set to `true` if you want to replace the document with the same id
});
// -----------
// Or directly
await fetch("https://petals.chat/api/memory/ingest-document", {
method: "POST",
body: JSON.stringify({
document: {
id: "abc",
content: "Hello, world!",
timestamp: new Date()
},
updateExisting: true // set to `true` if you want to replace the document with the same id
}),
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer your-petals-api-key-here"
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment