Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.memv.ai/llms.txt

Use this file to discover all available pages before exploring further.

Spaces are isolated containers for organizing memories. Each space has its own set of memories, files, and configuration.

Create a space

from memvai import Memv

client = Memv()

# Create a new space
response = client.spaces.create(
    name="Personal Assistant",
    description="Memories for my AI assistant"
)

space = response.space
print(f"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 spaces
response = client.spaces.list()

for space in response.spaces:
    print(f"{space.name} ({space.id})")

Retrieve a space

# Get space by ID
response = client.spaces.retrieve(space_id="space_abc123")

space = response.space
print(f"Name: {space.name}")
print(f"Description: {space.description}")

Update a space

# Update space details
response = client.spaces.update(
    space_id="space_abc123",
    name="Updated Name",
    description="Updated description"
)

space = response.space
print(f"Updated: {space.name}")

Delete a space

# Delete a space
response = client.spaces.delete(space_id="space_abc123")

if response.success:
    print("Space deleted successfully")
Deleting a space permanently removes all memories, files, and data associated with it. This action cannot be undone.

Get space statistics

# Get space stats
stats = 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")

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

# Usage
space_id = get_or_create_space(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

# Usage
space_ids = create_multiple_spaces([
    "User Preferences",
    "Chat History",
    "Knowledge Base"
])

Best practices

Create separate spaces for different use cases or users:
# User-specific spaces
user_space = client.spaces.create(
    name=f"User {user_id} - Preferences",
    description="User preferences and settings"
)

# Feature-specific spaces
chat_space = client.spaces.create(
    name="Chat History",
    description="Conversation memories"
)
Give spaces clear, descriptive names that indicate their purpose.
Regularly delete spaces that are no longer needed to manage costs.

Error handling

import memvai
from memvai import Memv

client = Memv()

try:
    response = client.spaces.create(name="My Space")
    space_id = response.space.id
    print(f"Created: {space_id}")
except memvai.AuthenticationError:
    print("Invalid API key")
except memvai.BadRequestError as e:
    print(f"Invalid request: {e.message}")
except memvai.APIError as e:
    print(f"API error: {e}")

Next steps

Memories

Add memories to your space

Files

Upload files to your space