A collection is a named container that groups related memories together. You create collections, assign memories to them, and scope searches to them.
Why Use Collections?
- Separate contexts: Keep work, personal, and project memories distinct
- Targeted search: Search only within relevant collections
- Access control: Different API keys can have different collection permissions
- Multi-tenancy: Isolate data for different users or customers
Creating Collections
Collection names are case-insensitive. “Work” and “work” are treated as duplicates.
from nebula import Nebula, Memory
nebula = Nebula()
collection = nebula.create_collection(
name="Research Papers",
description="Academic research documents"
)
Storing Memories in Collections
Always specify collection_id when storing memories:
nebula.store_memory(
Memory(
collection_id=collection.id,
content="Q4 planning meeting notes",
metadata={"type": "meeting"}
)
)
Searching Within Collections
# Search specific collection
results = nebula.search(query="deadlines", collection_ids=["Work"])
# Search multiple collections
results = nebula.search(query="notes", collection_ids=["Work", "Personal"])
# Search all accessible collections
results = nebula.search(query="important")
Search accepts collection names or UUIDs. When storing memories, collection_id must be a UUID.
Managing Collections
collections = nebula.list_collections(limit=50)
work_collections = nebula.list_collections(name="Work")
collection = nebula.get_collection(collection_id)
nebula.update_collection(
collection_id=collection.id,
name="Updated Name",
description="New description"
)
nebula.delete_collection(collection_id)
Deleting a collection removes its graph data and vector sources. The underlying memory records are disassociated from the collection, not deleted.
Patterns and Tips
| Pattern | When to Use |
|---|
| One collection per user | User-specific memory/context |
| One collection per project | Project-scoped documentation |
| One collection per data type | Different content types (docs, chats, notes) |