Skip to main content

pyvector support for vastbase

Project description

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_accum
  • floatvector_cmp
  • floatvector_gt
  • floatvector_ge
  • floatvector_ne
  • floatvector_eq
  • floatvector_le
  • floatvector_lt
  • floatvector_spherical_distance
  • floatvector_negative_inner_product
  • floatvector_l2_squared_distance
  • floatvector_avg
  • floatvector_sub
  • floatvector_add
  • floatvector_norm
  • floatvector_dims
  • l2_distance
  • inner_product
  • cosine_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 计算向量的余弦距离

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyvector_vastbase-1.0.2-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file pyvector_vastbase-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pyvector_vastbase-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1fca026eece48a3f696f651de0bf63408d1993861f164890d3fcd275dc744603
MD5 8a86efe3a557877747af1fa892a90661
BLAKE2b-256 30675cfd721513706565f63d26bfad5a7369c0deb7e9a717e3e13ae66eee65a5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page