Memory Management (mem0)
Relevant source files
The following files were used as context for generating this wiki page:
The Mem0Service manages long-term memory for the LV.AI AVA-Copilot by combining vector search, knowledge graphs, and key-value caching. It persists user preferences, task-specific insights, and professional expertise across different scopes to enhance the AI's proactivity and context-awareness.
Memory is structured into three primary levels: user-level for preferences, session-level for specific tasks, and agent-level for domain knowledge. This "Dual Memory" approach ensures that information relevant to a specific construction project remains isolated from global office-wide patterns and standards.
Sources: lib/memory/mem0.ts:1-5, CLAUDE.md:27, CLAUDE.md:52
Memory Scopes
The system defines two explicit scopes for categorizing and retrieving memories. This separation prevents the mixing of project-specific data with general office standards.
- Project Scope (
project): Contains insights or decisions relevant only to a specific construction project. - Global Scope (
global): Contains office-wide preferences, standard text modules, and recurring patterns.
Sources: lib/memory/mem0.ts:7-10, lib/memory/mem0.ts:46-48
Scope Architecture
The following diagram illustrates the relationship between the Mem0Service and the distinct memory scopes.
Sources: lib/memory/mem0.ts:7-50
Service Configuration
The Mem0Service requires specific configuration parameters to communicate with the external Mem0 API. These are typically provided via the createMem0Service factory function.
| Parameter | Type | Description |
|---|---|---|
apiKey | string | Authorization token for Mem0 API. |
userId | string | Unique identifier for the user. |
agentId | string | (Optional) Unique identifier for the AI agent. |
baseUrl | string | (Optional) API endpoint, defaults to https://api.mem0.ai/v1. |
Sources: lib/memory/mem0.ts:12-17, lib/memory/mem0.ts:32, README.md:85
Core Functionality
Remember
The remember method persists a new insight or decision. It sends a message to the Mem0 API, which processes and stores the content within the specified scope. If the scope is project, a projectId must be provided to associate the memory correctly.
Sources: lib/memory/mem0.ts:45-80
Search and Retrieval
The service provides methods to search through stored memories using vector queries. You can filter searches by scope and project ID to ensure relevance.
search(options): Executes a query against the memory store with a default limit of 10 entries.getProjectMemories(projectId): Shorthand for searching all memories associated with a specific project (limit 50).getGlobalMemories(): Shorthand for retrieving office-wide preferences (limit 50).
Sources: lib/memory/mem0.ts:85-132
Forget
The forget method removes a specific memory entry from the system using its unique identifier. This is critical for maintaining the accuracy of the knowledge base when decisions are retracted or corrected.
Sources: lib/memory/mem0.ts:137-147
Data Structures
The system uses standardized interfaces for memory entries and search requests to ensure consistency across the application.
export interface MemoryEntry {
id: string;
content: string;
scope: MemoryScope;
projectId?: string;
metadata?: Record<string, unknown>;
createdAt: string;
}
export interface SearchOptions {
query: string;
scope?: MemoryScope;
projectId?: string;
limit?: number;
}
Sources: lib/memory/mem0.ts:19-33
Integration with AI Prompts
The memory management system is integrated into the AI's reasoning process through project context. The system prompt dynamically includes projectContext if available, which is derived from the memories retrieved via Mem0Service. This allows the AI to remain "proactive and autonomous" by reconciling information from the chat history and the mem0 memory store.
Sources: lib/ai/prompts.ts:71-85, CLAUDE.md:121-125
Summary
Memory Management in LV.AI utilizes the mem0 service to provide a persistent, context-aware experience for AVA (Ausschreibung, Vergabe, Abrechnung) tasks. By separating project-specific insights from global professional standards, the system ensures data integrity and professional compliance (VOB/ÖNORM/SIA) across various construction projects. The service effectively bridges the gap between ephemeral chat interactions and long-term project knowledge.
Sources: lib/memory/mem0.ts:1-5, CLAUDE.md:52, README.md:32