Spaces are isolated containers for organizing memories. Each space has its own set of memories, files, and configuration.
Create a space
from memvai import Memvclient = Memv()# Create a new spaceresponse = client.spaces.create( name="Personal Assistant", description="Memories for my AI assistant")space = response.spaceprint(f"Created space: {space.id}")
import Memv from 'memvai';const client = new Memv();// Create a new spaceconst response = await client.spaces.create({ name: 'Personal Assistant', description: 'Memories for my AI assistant',});const { space } = response;console.log(`Created space: ${space.id}`);
Response structure
The response contains a space object with the following fields:
id - Unique space identifier
name - Space name
description - Space description
created_at - Creation timestamp
updated_at - Last update timestamp
List spaces
# List all spacesresponse = client.spaces.list()for space in response.spaces: print(f"{space.name} ({space.id})")
// List all spacesconst response = await client.spaces.list();for (const space of response.spaces) { console.log(`${space.name} (${space.id})`);}
Retrieve a space
# Get space by IDresponse = client.spaces.retrieve(space_id="space_abc123")space = response.spaceprint(f"Name: {space.name}")print(f"Description: {space.description}")
// Get space by IDconst response = await client.spaces.retrieve('space_abc123');const { space } = response;console.log(`Name: ${space.name}`);console.log(`Description: ${space.description}`);
Deleting a space permanently removes all memories, files, and data associated with it. This action cannot be undone.
Get space statistics
# Get space statsstats = client.spaces.get_stats()print(f"Total memories: {stats.total_memories}")print(f"Total files: {stats.total_files}")print(f"Storage used: {stats.storage_bytes} bytes")
// Get space statsconst stats = await client.spaces.getStats();console.log(`Total memories: ${stats.total_memories}`);console.log(`Total files: ${stats.total_files}`);console.log(`Storage used: ${stats.storage_bytes} bytes`);
Common patterns
Create space if not exists
def get_or_create_space(client: Memv, name: str) -> str: """Get existing space by name or create new one.""" # List existing spaces response = client.spaces.list() # Find by name for space in response.spaces: if space.name == name: return space.id # Create new space response = client.spaces.create(name=name) return response.space.id# Usagespace_id = get_or_create_space(client, "My App")
async function getOrCreateSpace( client: Memv, name: string): Promise<string> { // List existing spaces const { spaces } = await client.spaces.list(); // Find by name const existing = spaces.find(s => s.name === name); if (existing) { return existing.id; } // Create new space const { space } = await client.spaces.create({ name }); return space.id;}// Usageconst spaceId = await getOrCreateSpace(client, 'My App');
Batch operations
def create_multiple_spaces(names: list[str]) -> list[str]: """Create multiple spaces.""" space_ids = [] for name in names: response = client.spaces.create(name=name) space_ids.append(response.space.id) return space_ids# Usagespace_ids = create_multiple_spaces([ "User Preferences", "Chat History", "Knowledge Base"])