Skip to Content

Memories

Memories are the core of zkstash. The SDK allows you to easily extract new memories from conversations and search through existing ones.

Creating Memories

To create memories, you simply pass the conversation history to the createMemory method. The zkstash backend will automatically analyze the conversation using your registered schemas and extract relevant structured data.

const response = await client.createMemory({ agentId: "agent-007", conversation: [ { role: "user", content: "I am allergic to peanuts." }, { role: "assistant", content: "Understood, I will remember that." } ] }); console.log("Created memories:", response.created);

Parameters

  • agentId: The ID of the agent storing the memory.
  • conversation: Array of message objects ({ role, content }).
  • schemas (Optional): Array of schema names to limit extraction to specific schemas.

Searching Memories

You can search for memories using natural language queries. The system uses semantic search to find the most relevant memories.

const results = await client.searchMemories({ query: "dietary restrictions", filters: { agentId: "agent-007", kind: "UserProfile" // Optional: filter by schema type } }); console.log("Found memories:", results.memories);

Filters

  • agentId: Filter by agent.
  • threadId: Filter by conversation thread.
  • kind: Filter by schema name (e.g., “UserProfile”).
  • tags: Filter by tags.

Mode

  • mode: The mode to use for the search. Can be “raw”, “answer”, or “map”.
    • raw: Returns the raw memories as JSON objects.
    • answer: Returns the memories as a list of answers.
    • map: Returns the memories as a map of schema names to answers.

Deleting Memories

You can delete memories using the deleteMemory method.

await client.deleteMemory({ id: "memory-007" });
Last updated on