JavaScript SDK
Official JavaScript and Node.js SDK for Memoid. Add persistent AI memory, semantic search, and knowledge graphs to your JS apps.
Installation
npm install @memoid/sdk Quick Start
import { MemoryClient } from "@memoid/sdk";
const client = new MemoryClient("your-api-key");
// Add a memory
await client.add([
{ role: "user", content: "I love hiking and Italian food" },
{ role: "assistant", content: "Great! I'll remember that." }
], { user_id: "user_123" });
// Search memories
const results = await client.search("What food does the user like?", {
user_id: "user_123"
});
// Recall context (memories + graph in one call)
const context = await client.recall("Tell me about the user", {
user_id: "user_123",
include_graph: true
}); Configuration
const client = new MemoryClient("your-api-key", {
baseUrl: "https://api.memoid.dev", // default
timeout: 30000 // 30s default
}); For self-hosted instances, set baseUrl to your API URL.
Memories
Add Memories
const memories = await client.add(
[
{ role: "user", content: "My manager Sarah works at TechCorp" }
],
{
user_id: "user_123",
project_id: "proj_abc",
metadata: { source: "chat" },
extract_graph: true // extract entities to knowledge graph
}
); Get a Memory
const memory = await client.get("memory_id"); List Memories
const memories = await client.getAll({
user_id: "user_123",
limit: 50
}); Update a Memory
await client.update("memory_id", "Updated memory text", { source: "edit" }); Delete
await client.delete("memory_id");
await client.deleteAll({ user_id: "user_123" }); History
const history = await client.history("memory_id"); Search
const results = await client.search("food preferences", {
user_id: "user_123",
limit: 5,
threshold: 0.7
});
for (const result of results) {
console.log(`${result.memory} (score: ${result.score})`);
} Recall
Unified context retrieval — combines memory search with knowledge graph data in a single call. Ideal for agents.
const context = await client.recall("What do I know about John?", {
user_id: "user_123",
include_graph: true,
memory_limit: 10,
threshold: 0.3
});
console.log(context.memories); // relevant memories
console.log(context.entities); // related graph entities
console.log(context.relationships); // entity relationships User Context
Get all memories and graph data for a user in a single call — ideal for rendering a graph + memory list in the UI.
const context = await client.getUserContext({ user_id: "user_123" });
console.log(context.memories); // all memories
console.log(context.entities); // all graph entities
console.log(context.relationships); // all relationships
console.log(context.stats); // { total_memories, total_entities, total_relationships } Knowledge Graph
Extract Knowledge
const result = await client.extractKnowledge(
"Sarah is the CEO of TechCorp. She founded it with Mike.",
{ user_id: "user_123" }
);
// result.entities: [{name: "Sarah", type: "person"}, ...]
// result.relationships: [{subject: "Sarah", predicate: "ceo_of", object: "TechCorp"}, ...] Add Entity & Relationship
await client.addEntity("Acme Corp", "organization");
await client.addRelationship("John", "person", "works_at", "Acme Corp", "organization"); Query & Search
const related = await client.graphQuery("John", 2); // 2 hops
const found = await client.graphSearch("tech companies"); Delete Entity
await client.deleteEntity("John"); // also removes relationships Batch Operations
await client.batchUpdate([
{ id: "mem_1", memory: "Updated text" },
{ id: "mem_2", memory: "Another update" }
]);
await client.batchDelete({ memory_ids: ["mem_1", "mem_2"] }); Projects
const project = await client.createProject("My Project");
const projects = await client.getProjects();
await client.updateProject("proj_id", { name: "Renamed" });
await client.deleteProject("proj_id"); Usage
const stats = await client.getUsageStats();
const daily = await client.getUsageDaily(30); TypeScript
All methods are fully typed. Import types directly:
import type { Memory, SearchResult, RecallResult, GraphEntity } from "@memoid/sdk";