# Technical Implementation

The AI integration in Vult is structured to provide real-time AI chat, file-based AI processing, memory retention, and batch processing. The technical implementation consists of frontend components, backend APIs, database interactions, and AI model processing pipelines.

This section details how chat requests, file processing, batch execution, and memory retention are handled within Vult AI.

### **1. AI Chat Request Handling**

<figure><img src="/files/0XwRSpmEQWBg5YiZBMfd" alt=""><figcaption></figcaption></figure>

#### **Step 1: User Submits a Chat Request**

Users interact with the Vult AI Chat Interface by entering a text prompt, selecting an AI model. and optionally attaching a file.

#### **Step 2: File Processing (If Applicable)**

If the user attaches a file:

* The file is **privately shared** using **AuthTicket & LookupHash**.
* AI **downloads the file** securely.
* The **file content is analyzed** using the selected AI model.

#### **Step 3: AI Model Processing**

The request is sent to the **backend API** for processing and the **selected AI model** generates a response.

#### **Step 4: Response Storage**

Chat responses are saved in AI Chat Folder and File-based responses are stored in AI Agent Folder.

### **2. Backend API Endpoints**

#### **1. Create Chat API**

Handles **real-time AI chat interactions**.

**Endpoint:**

```bash
POST /api/chat/create
```

**Request Payload:**

```json
{
  "shareInfoUrls": "string",
  "prompt": "string",
  "model": "string",
  "isFileProcessing": "bool",
  "fileType": "string"
}
```

**Response:**

```json
{
  "status": "success",
  "data": {
    "response": "AI generated response",
    "fileUrl": "https://vult.ai/file/response.pdf"
  }
}
```

#### **2. Batch Processing API**

Processes **multiple files in one request** for AI-based batch execution.

**Endpoint:**

```bash
POST /api/batch/process
```

#### **3. Memory API (Mem0 AI)**

Retrieves **past user interactions** to maintain context across sessions.

**Endpoint:**

```bash
POST /api/memory/search
```

### **3. Backend Implementation Details**

#### **File Upload & Secure Sharing**

Files are not uploaded to third-party AI models. Instead, a secure private share is created using an AuthTicket, which is a unique Base64-encoded authentication token, and a LookupHash, which serves as a reference hash to identify the file.&#x20;

The AI model then downloads and processes the file.

#### **AI Model Processing Pipeline**

The process begins with the user prompt and any attached file being sent to the Backend API. The backend determines the selected AI model. If a file is attached, it is downloaded from Vult Storage.&#x20;

The AI model then generates a response, which can be text, image, or document-based. This response is stored and displayed in the user interface.

#### **Memory Retention (Mem0 AI Integration)**

The Mem0 AI API stores previous chat sessions. When a user starts a new conversation, the AI retrieves contextually relevant past interactions.&#x20;

The retrieved memory is appended to the current prompt before the AI processes it.

### **4. Batch Processing Implementation**

#### **Step 1: User Initiates a Batch Request**

The user begins by selecting a folder containing multiple files. The AI Agent then creates a batch request for processing these files.

#### **Step 2: Backend Processing**

All selected files are securely downloaded. These files, along with any user-defined instructions, are packaged into a JSONL file. This JSONL file is then sent to the OpenAI Batch API for processing.

#### **Step 3: Response Handling**

The batch API processes each file independently. The AI responses are stored as individual text files in the AI Agent Folder. For large batches, processing can take up to 24 hours.

### **5. Database & Storage Design**

#### **AI Chat Storage (NoSQL Database Schema)**

Chat interactions between users and the AI agent are stored in a NoSQL database. The schema is designed to be flexible, allowing for variable message formats, timestamps, metadata, and session grouping.

```json
{
  "user_id": "123456",
  "session_id": "abc789",
  "messages": [
    {
      "timestamp": "2025-03-17T12:34:56Z",
      "user_input": "What is my name?",
      "ai_response": "Your name is Jack."
    }
  ]
}
```

#### **AI Agent Storage (File System-Based)**

While conversations are stored in the database, media assets and outputs generated by the AI agent are saved on the file system for efficient retrieval, archival, and offline access.

* Responses are stored in the **AI Agent Folder** for future retrieval.
* Text responses are stored as **.txt or .pdf files**.
* Image-based responses are **processed and saved** in the **AI Image Directory**.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.zus.network/zus-docs/webapps/vult/vult-ai/technical-implementation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
