memoer
Version:
Memory management system for LLMs
38 lines • 1.06 kB
JavaScript
import { createConversation } from "./managers/conversation";
class InMemoryStore {
constructor() {
this.store = new Map();
}
get(id) {
const memory = this.store.get(id);
if (!memory) {
throw new Error(`Memory with id ${id} not found`);
}
return memory;
}
set(id, memory) {
this.store.set(id, memory);
}
has(id) {
return this.store.has(id);
}
create(config) {
if (this.has(config.id)) {
throw new Error(`Memory with id ${config.id} already exists. Use a different ID or retrieve the existing memory.`);
}
const memory = createMemoryInstance(config);
this.set(config.id, memory);
return memory;
}
}
function createMemoryInstance(config) {
const conversation = createConversation(config.managers?.conversation || {});
return {
id: config.id,
config,
conversation
};
}
// singleton
export const memoryStore = new InMemoryStore();
//# sourceMappingURL=store.js.map