pyvector-vastbase
pyvector support for vastbase
Supports SQLAlchemy
Run:
pip install pyvector-vastbase
And follow the instructions for your database library:
SQLAlchemy
映射向量列
from vastbase.sqlalchemy import FloatVector
class Item(Base):
embedding = mapped_column(FloatVector(3))
插入向量
item = Item(embedding=[1, 2, 3])
session.add(item)
session.commit()
查询近似向量 使用欧几里得距离操作符 l2_distance(<->)
session.scalar(select(Item).order_by(Item.embedding.l2_distance([3, 1, 2])).limit(5))
还支持以下操作符
negative_inner_product(<#>)consine_distance(<=>add(+)sub(-)
查询向量的欧几里得距离
session.scalar(select(Item.embedding.l2_distance([3, 1, 2])))
查询近似向量(使用欧几里得距离)
session.scalar(select(Item).filter(Item.embedding.l2_distance([3, 1, 2]) < 5))
函数调用
session.scalar(session.query(floatvector_combine([1.0,2.0,3.0], [4,5,6])))
还支持以下函数(函数说明请参考使用手册)
floatvector_accumfloatvector_cmpfloatvector_gtfloatvector_gefloatvector_nefloatvector_eqfloatvector_lefloatvector_ltfloatvector_spherical_distancefloatvector_negative_inner_productfloatvector_l2_squared_distancefloatvector_avgfloatvector_subfloatvector_addfloatvector_normfloatvector_dimsl2_distanceinner_productcosine_distance
近似最近邻索引
index = Index(
'my_index',
Item.embedding,
postgresql_using='hnsw',
postgresql_with={'m': 16, 'ef_construction': 64},
postgresql_ops={'embedding': 'floatvector_l2_ops'}
)
# or
index = Index(
'my_index',
Item.embedding,
postgresql_using='ivfflat',
postgresql_with={'ivf_nlist': 100},
postgresql_ops={'embedding': 'floatvector_l2_ops'}
)
索引构建还支持以下操作符
floatvector_l2_ops计算向量的欧几里得距离floatvector_ip_ops计算向量的内积floatvector_consine_ops计算向量的余弦距离
Metadata
Release files for pyvector-vastbase 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyvector_vastbase-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for pyvector_vastbase-1.0.2-py3-none-any.whl |
Release files / pyvector_vastbase-1.0.2-py3-none-any.whl
| Download URL | pyvector_vastbase-1.0.2-py3-none-any.whl |
|---|---|
| Size | 7.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1fca026eece48a3f696f651de0bf63408d1993861f164890d3fcd275dc744603
|
|
BLAKE2b-256 checksum How to use checksums |
30675cfd721513706565f63d26bfad5a7369c0deb7e9a717e3e13ae66eee65a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.6
|
Security for pyvector-vastbase 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.