Last active
June 27, 2025 08:08
-
-
Save iamarcel/0da3e9c1179e9635caacb9dd84037a58 to your computer and use it in GitHub Desktop.
Example: Ingesting documents into your Petals memory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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