Mochow Python SDK
raw JSON → 2.4.0 verified Fri May 01 auth: no python
Python SDK for Mochow, a vector database service. Current version 2.4.0, requires Python >=3.7. Released on PyPI with regular updates.
pip install pymochow Common errors
error ImportError: cannot import name 'MochowClient' from 'pymochow' ↓
cause Incorrect import path; MochowClient is in the client submodule.
fix
Use: from pymochow.client import MochowClient
error pymochow.exceptions.ValidationError: vector dimension must match collection dimension ↓
cause Inserted document vector length does not match the collection's dimension setting during creation.
fix
Ensure every inserted document's vector length equals the collection's dimension (e.g., for 128-dim, use [0.1]*128).
error requests.exceptions.HTTPError: 401 Client Error: Unauthorized ↓
cause Missing or incorrect API key.
fix
Check that MOCHOW_API_KEY environment variable is set or pass a valid api_key to MochowClient.
error TypeError: __init__() got multiple values for argument 'endpoint' ↓
cause Passing endpoint both as positional argument and as keyword argument.
fix
Use either positional (deprecated) or keyword only. Preferred: MochowClient(endpoint='...', api_key='...')
Warnings
breaking In version 2.x, the client initialization changed from positional arguments to keyword arguments. Using old-style instantiation will fail. ↓
fix Use MochowClient(endpoint='...', api_key='...') with explicit keyword arguments.
deprecated The 'search' method's 'top_k' parameter is deprecated in favor of 'limit' starting from version 2.3.0. ↓
fix Use client.search(..., limit=10) instead of top_k=10.
gotcha Document vector must be a list of floats with length exactly matching collection dimension. Providing an integer list or wrong dimension raises a validation error. ↓
fix Ensure vectors are lists of floats (e.g., [0.1, 0.2, ...]) and length equals the collection's dimension.
gotcha API key is required for authentication; omitting it or using an invalid key results in 401 errors. ↓
fix Set environment variable MOCHOW_API_KEY or pass api_key as a constructor argument.
Imports
- MochowClient wrong
from pymochow import MochowClientcorrectfrom pymochow.client import MochowClient - Collection
from pymochow.model.collection import Collection - Document
from pymochow.model.document import Document
Quickstart
import os
from pymochow.client import MochowClient
from pymochow.model.collection import Collection
from pymochow.model.document import Document
# Replace with your Mochow endpoint and API key
endpoint = os.environ.get('MOCHOW_ENDPOINT', 'http://localhost:8080')
api_key = os.environ.get('MOCHOW_API_KEY', '')
client = MochowClient(endpoint=endpoint, api_key=api_key)
# Create a collection
collection = Collection(name='my_collection', dimension=128)
client.create_collection(collection)
# Insert documents
doc1 = Document(id='1', vector=[0.1]*128, metadata={'title': 'doc1'})
doc2 = Document(id='2', vector=[0.2]*128, metadata={'title': 'doc2'})
client.insert(collection.name, [doc1, doc2])
# Search
results = client.search(collection.name, query_vector=[0.15]*128, top_k=2)
for r in results:
print(r.id, r.score)