VectorDB Service
Overview
The VectorDB Service (VectorDBService
) provides comprehensive vector database management functionality for the Kamiwaza AI Platform. Located in kamiwaza_client/services/vectordb.py
, this service handles vector storage, retrieval, and similarity search operations.
Key Features
- Vector Database Management
- Vector Storage and Retrieval
- Similarity Search
- Simplified Vector Operations
- Database Lifecycle Management
Vector Database Management
Available Methods
create_vectordb(config: CreateVectorDB) -> VectorDB
: Create new vector databaseget_vectordbs() -> List[VectorDB]
: List all vector databasesget_vectordb(vectordb_id: UUID) -> VectorDB
: Get database detailsremove_vectordb(vectordb_id: UUID)
: Remove vector database
# Create vector database
vectordb = client.vectordb.create_vectordb(CreateVectorDB(
name="my-vectors",
dimension=768,
metric="cosine"
))
# List databases
databases = client.vectordb.get_vectordbs()
# Get specific database
db = client.vectordb.get_vectordb(vectordb_id)
# Remove database
client.vectordb.remove_vectordb(vectordb_id)
Vector Operations
Available Methods
insert_vectors(vectordb_id: UUID, vectors: List[Vector]) -> InsertResponse
: Insert vectorssearch_vectors(vectordb_id: UUID, query: List[float], k: int = 10) -> List[SearchResult]
: Search vectorsinsert(vectordb_id: UUID, data: Dict[str, Any]) -> InsertResponse
: Simplified vector insertionsearch(vectordb_id: UUID, query: str, k: int = 10) -> List[SearchResult]
: Simplified vector search
# Insert vectors
response = client.vectordb.insert_vectors(
vectordb_id=db_id,
vectors=[
Vector(id="vec1", vector=[0.1, 0.2, 0.3], metadata={"text": "example"})
]
)
# Search vectors
results = client.vectordb.search_vectors(
vectordb_id=db_id,
query=[0.1, 0.2, 0.3],
k=5
)
# Simplified operations
# Insert with automatic vector generation
response = client.vectordb.insert(
vectordb_id=db_id,
data={"text": "example text", "metadata": {"source": "doc1"}}
)
# Search with automatic query vector generation
results = client.vectordb.search(
vectordb_id=db_id,
query="example query",
k=5
)
Error Handling
The service includes built-in error handling for common scenarios:
try:
vectordb = client.vectordb.create_vectordb(config)
except DimensionError as e:
print(f"Invalid dimension: {e}")
except MetricError as e:
print(f"Invalid metric: {e}")
except APIError as e:
print(f"Operation failed: {e}")
Best Practices
- Choose appropriate vector dimensions based on your embedding model
- Select the right similarity metric for your use case
- Use batch operations for better performance
- Include relevant metadata with vectors
- Clean up unused databases
- Use simplified operations when working with text data
- Monitor database size and performance
- Implement proper error handling for vector operations