Architecture Overview
High-Level System Components
The memory retention system consists of the following components:

Frontend (Vult AI Chat UI)
Users interact with AI via the chat interface.
Prompts and responses are stored in the AI Chat Folder.
Backend (AI Processing & Memory Storage)
Handles user queries and processes AI-generated responses.
Uses Mem0 AI API for memory storage and retrieval.
Stores structured chat logs in a database or file system.
Memory Storage Layer (Mem0 AI API)
Stores chat histories and user data.
Retrieves relevant memories based on user input and prompt context.
Ensures quick access to stored interactions for seamless responses.
Backend Implementation
1. Data Structures (Go Structs for Memory Storage)
type Chat struct {
ShareInfoUrls []string `json:"share_info_urls"`
ShareInfoIds string `json:"share_info_ids"`
Prompt string `json:"prompt"`
Model string `json:"model"`
IsFileProcessing bool `json:"is_file_processing"`
MasterPrompt string `json:"master_prompt"`
OpenAiMessages []map[string]interface{} `json:"open_ai_messages"`
DeepSeekMessages []map[string]interface{} `json:"deep_seek_messages"`
FileType string `json:"file_type"`
IsAgentInput bool `json:"is_agent_input"`
WebSearch bool `json:"web_search"`
}
This struct represents a chat session in Vult AI. The key fields are:
Prompt
: Stores the user’s latest query.Model
: The AI model used for processing.OpenAiMessages
: Stores previous interactions with OpenAI models.DeepSeekMessages
: Stores previous interactions with DeepSeek models.IsAgentInput
: Indicates if the request is from AI Agent (file-based processing).
2. Memory Retrieval via Mem0 AI
func retrieveMemory(userID string, prompt string) (string, error) {
memoryClient := memory.NewMem0Client(config.Configuration.Mem0ApiKey)
memoryResponse, err := memoryClient.SearchMemory(userID, prompt)
if err != nil {
logger.LogError("AI Chat: Failed to search memory", zap.Error(err))
return "", err
}
if memoryResponse != nil {
return memoryResponse.Memories, nil
}
return "", nil
}
This function:
Initializes the Mem0 API client.
Calls
SearchMemory()
to fetch previously stored interactions.If memory exists, it returns retrieved context to be appended to the user prompt.
3. AI Model Processing with Memory Context
func processChatRequest(ctx context.Context, chatInput Chat) (Response, error) {
memoryContext, _ := retrieveMemory(chatInput.UserID, chatInput.Prompt)
chatInput.Prompt = memoryContext + "\nUser Question: " + chatInput.Prompt
res, err := aiAgentService.CreateChat(ctx, authHeaders, chatInput)
if err != nil {
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return nil, err
}
return res, nil
}
This function:
Calls
retrieveMemory()
to fetch relevant past interactions.Appends retrieved memory to the current user prompt.
Passes the enriched prompt to the AI model for response generation.
Returns the processed response to the Vult AI UI.
Last updated