Skip to main content

Advanced Configuration

Memoer offers a variety of advanced configuration options to customize memory behavior for your specific use case.

Persistence Options

You can configure Memoer to persist conversations to storage:

import { memoer, MemoryConfig } from "memoer";

const memory = memoer.createMemory({
id: "persistent-conversation",
systemMessage: {
role: "system",
content: "You are a helpful assistant."
},
persistence: {
type: "file",
options: {
directory: "./conversation-data"
}
}
});

This allows conversations to be saved and restored across application restarts.

Custom Memory Strategies

You can also implement custom memory strategies:

import { memoer, MemoryConfig, BaseMemoryStrategy } from "memoer";

// Create a custom strategy
class PriorityMessageStrategy extends BaseMemoryStrategy {
constructor(options) {
super();
this.priorityKeywords = options.priorityKeywords || [
"important",
"critical",
"remember"
];
}

process(messages) {
// Always keep system message
const systemMessage = messages.find((msg) => msg.role === "system");
const result = systemMessage ? [systemMessage] : [];

// Filter messages containing priority keywords
const priorityMessages = messages.filter((msg) => {
if (msg.role === "system") return false;
return this.priorityKeywords.some((keyword) =>
msg.content.toLowerCase().includes(keyword)
);
});

// Add the last 5 messages for recency
const recentMessages = messages.slice(-5);

// Combine and deduplicate messages
return [...result, ...priorityMessages, ...recentMessages].filter(
(msg, index, self) => index === self.findIndex((m) => m === msg)
);
}
}

// Use the custom strategy
const memory = memoer.createMemory({
id: "custom-strategy-example",
systemMessage: {
role: "system",
content: "You are a helpful assistant."
},
managers: {
conversation: {
strategy: new PriorityMessageStrategy({
priorityKeywords: ["important", "remember", "critical"]
})
}
}
});

Vector Database Integration

For more advanced retrieval capabilities, integrate with vector databases:

import { memoer, MemoryConfig } from "memoer";

const memory = memoer.createMemory({
id: "vector-enhanced-memory",
systemMessage: {
role: "system",
content: "You are a helpful assistant."
},
managers: {
conversation: {
strategy: ConversationStrategy.SLIDING_WINDOW,
slidingWindowSize: 10
},
vectorStore: {
provider: "pinecone",
options: {
apiKey: process.env.PINECONE_API_KEY,
environment: "us-west-1",
index: "conversation-memory"
},
embeddingProvider: "openai",
embeddingOptions: {
apiKey: process.env.OPENAI_API_KEY,
model: "text-embedding-3-small"
}
}
}
});

// Retrieve semantically relevant messages from past conversations
const relevantContext = await memory.vectorStore.search(
"How do I reset my password?",
{ limit: 3 }
);

Multi-Agent Memory Management

Configure shared memory between multiple agents:

import { memoer, MemoryConfig } from "memoer";

// Create a shared memory instance
const sharedMemory = memoer.createMemory({
id: "shared-agent-memory",
systemMessage: {
role: "system",
content: "This is a multi-agent conversation."
}
});

// Agent-specific views of the shared memory
const customerAgentMemory = memoer.createAgentView(sharedMemory, {
agentId: "customer-agent",
systemMessage: {
role: "system",
content: "You are a customer support agent helping users with their issues."
}
});

const technicalAgentMemory = memoer.createAgentView(sharedMemory, {
agentId: "technical-agent",
systemMessage: {
role: "system",
content:
"You are a technical support specialist with deep product knowledge."
}
});

These advanced configurations allow you to fine-tune Memoer's behavior to meet the specific requirements of your application.