MariaDB Vector
Integrate MariaDB's VECTOR type with SQL Alchemy and SQL Model
Installation
pip install mariadb-vector
Usage
Add a vector column
from sqlmodel import SQLModel, Field, Column
from mariadb_vector import Vector
class Item(SQLModel, table=True):
embedding: list[float] = Field(sa_column=Column(Vector(3)))
Insert a vector
item = Item(embedding=[0.1, 0.2, 0.3])
session.add(item)
session.commit()
Vector Search
The following functions are available for calculating vector distances:
vec_from_seq(array: Sequence)
- Converts a Python list or NumPy array into a database-compatible vector function.
vec_distance(v1, v2)
- Calculates a general distance between two vectors.
vec_distance_euclidean(v1, v2)
- Calculates the Euclidean distance between two vectors.
vec_distance_cosine(v1, v2)
- Calculates the cosine distance between two vectors.
# Assume `engine` is already created and connected to your database.
with Session(engine) as session:
target_vector = [0.1, 0.2, 0.3]
query = (
select(Item.id)
.order_by(vec_distance_euclidean(Item.embedding, target_vector))
.limit(2)
)
result = session.exec(query).all()
print(result)
Contributing
- This library is inspired by the pgvector-python and is built to bring similar functionality to MariaDB.
- Any contributions, bug reports, or improvements are welcome!
- Feel free to open issues or submit pull requests.
Release files for mariadb-vector 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mariadb_vector-0.3.0.tar.gz | 4.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mariadb_vector-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.1 kB
Release files / mariadb_vector-0.3.0.tar.gz
| Download URL | mariadb_vector-0.3.0.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
61ac4da85f51d41674053c670cf884b378ce12c5f7ad88da014ca62fc70a65ab
|
|
BLAKE2b-256 checksum How to use checksums |
6daa466a5cd7c884df6e43d6f9722544fe16e42f00aafaea25e54cca07c2b6cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
pdm/2.23.0 CPython/3.13.2 Linux/6.8.0-1021-azure
|
Release files / mariadb_vector-0.3.0-py3-none-any.whl
| Download URL | mariadb_vector-0.3.0-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b278f07210dbbdb048cb4eafe50e7e06d8e65586a6289679e75d5fa3559af0b5
|
|
BLAKE2b-256 checksum How to use checksums |
5cd698b4067d7e3608780b5cbd558351b827f06095de8d73637b29a07dd0f131
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
pdm/2.23.0 CPython/3.13.2 Linux/6.8.0-1021-azure
|