lancedb 使用minio s3 作为存储

lancedb 是一个灵活高效的向量数据库,提供了方便的存储模式支持(本地以及对象存储的)以下是关于集成minio s3 的一个简单示例

代码

  • s3-lance.py
import lancedb
from lancedb.pydantic import LanceModel, Vector

# 注意格式,如果是http 的需要添加 "allow_http":"true",
db = lancedb.connect(
    "s3://lancedb",
    storage_options= {
        "storage_type":'minio',
        "endpoint":'http://localhost:9000',
        "access_key":'minio',
        "secret_key":'minio123',
        "bucket":'lancedb',
        "allow_http":"true",
        "region":'us-east-1'
    }
)

class Item(LanceModel):
    face_id: str
    age: int
    vector: Vector(2)

table = db.create_table("faces", schema=Item.to_arrow_schema(),mode="overwrite")

items = [{"face_id": "face1", "age": 20, "vector": [0.1, 0.2]},{"face_id": "face2", "age": 30, "vector": [0.3, 0.5]}]

table.add(items)

search_items = table.search([0.3,0.5]).to_list()

print(search_items)
  • 效果

说明

基于对象存储的查询模式可以简化我们的部署,实现灵活的数据存储机制,当然也是有一些缺陷的,比如延迟

参考资料

https://github.com/lancedb/lancedb

https://lancedb.github.io/lancedb/guides/storage/

https://lancedb.github.io/lance/

https://lancedb.github.io/lancedb/concepts/storage/#tradeoffs

posted on 2025-03-30 08:00  荣锋亮  阅读(247)  评论(0)    收藏  举报

导航