Separate public mo-vector package lab

This example installs public PyPI mo-vector==0.1.13 and imports MoVectorClient. General matrixone-python-sdk Client/Session is a different interface; see the SDK guide. Development source and public distributions can have different APIs. This lab needs no source-repository access permission.

Install and prepare

python -m pip install mo-vector==0.1.13 SQLAlchemy==2.0.43 PyMySQL==1.1.1

Use Python 3.12 and a dedicated database. Set MO_VECTOR_URI to its SQLAlchemy MySQL/PyMySQL URI, supplying credentials through environment configuration. sdk_public_vector_lab must not exist; the script checks rather than using drop_existing_table=True.

Runnable vector example

The distribution’s DistanceStrategy enum exposes L2. This lab explicitly uses L2 distance, smaller is closer, not a cosine score. Fixed three-dimensional vectors need no model download. Expected a distance is zero and b is sqrt(2). Independent SQL verifies document, embedding and metadata, followed by a deletion check.

import json
import math
import os
from sqlalchemy import create_engine, text
from mo_vector.client import MoVectorClient
from mo_vector.client.vector_client import DistanceStrategy

uri = os.environ["MO_VECTOR_URI"]
engine = create_engine(uri)
client = None
created = False
try:
    with engine.connect() as connection:
        assert connection.exec_driver_sql("SHOW TABLES LIKE 'sdk_public_vector_lab'").first() is None
    client = MoVectorClient(connection_string=uri, table_name="sdk_public_vector_lab",
                            vector_dimension=3, distance_strategy=DistanceStrategy.L2,
                            drop_existing_table=False)
    created = True
    inserted = client.insert(ids=["a", "b"], texts=["dog", "fish"],
                             embeddings=[[1, 0, 0], [0, 1, 0]],
                             metadatas=[{"kind": "animal"}, {"kind": "animal"}])
    assert inserted == ["a", "b"]
    matches = client.query([1, 0, 0], k=2)
    assert [row.id for row in matches] == ["a", "b"]
    assert abs(matches[0].distance) < 1e-6
    assert abs(matches[1].distance - math.sqrt(2)) < 1e-6
    with engine.connect() as connection:
        rows = connection.execute(text("SELECT id,document,embedding,meta "
                                       "FROM sdk_public_vector_lab ORDER BY id")).all()
    assert [(row[0], row[1], json.loads(row[2]), json.loads(row[3])) for row in rows] == [
        ("a", "dog", [1, 0, 0], {"kind": "animal"}),
        ("b", "fish", [0, 1, 0], {"kind": "animal"}),
    ]
    client.delete(ids=["a", "b"])
    assert client.query([1, 0, 0], k=2) == []
    print("public mo-vector 0.1.13 insert/L2/readback/delete verified")
finally:
    try:
        if created:
            client.drop_table()
    finally:
        # 0.1.13 has no public close method; this pinned example releases its Engine.
        if client is not None:
            client._bind.dispose()
        engine.dispose()

Output is public mo-vector 0.1.13 insert/L2/readback/delete verified. This exact code executed on Python 3.12.14, MO v4.2.5 and public distribution 0.1.13 on 2026-10-14. It removes only its newly created lab table.

0.1.13 has no public close method. This pinned example releases the internal _bind Engine; that attribute is not a cross-version API. create_full_text_index/full_text_query/mix_query may differ from development snapshots. Fulltext ranking, hybrid reranking and filters are not certified here.

0.1.13 default table creation automatically creates an IVF index (lists=1000, vector_l2_ops). This is not an index-free setup. SHOW INDEX confirms vec_idx_embedding. The lab checks vector results and index existence, not index training, plan use, ANN acceleration, performance or every filter/metric combination. Inspect SHOW INDEX and EXPLAIN separately. Method existence does not replace retrieval-result or plan acceptance.