向量数据库的使用

向量数据库

向量数据库是一种专门用于存储、管理和查询高维向量数据的数据库系统。随着人工智能和机器学习的广泛应用,向量数据库在处理非结构化数据(如文本、图像、音频和视频等)的任务中变得越来越重要。本文将介绍快速使用Chroma

安装

安装chromadb向量数据库

pip install chromadb 

创建链接

创建客户端

import chromadb
chroma_client = chromadb.Client()

创建集合

Chroma数据结构,包括集合、文档和Embedding。

collection = chroma_client.create_collection(name="my_collection")

添加文档

添加文档到集合中

collection.add(
    documents=[
        "This is a document about pineapple",
        "This is a document about oranges"
    ],
    ids=["id1", "id2"]
)

搜索

搜索文档并指定返回文档数

results = collection.query(
    query_texts=["This is a query document about hawaii"], # Chroma will embed this for you
    n_results=2 # how many results to return
)
print(results)

查看结果

可以看到夏威夷和菠萝更相似。

{
  'documents': [[
      'This is a document about pineapple',
      'This is a document about oranges'
  ]],
  'ids': [['id1', 'id2']],
  'distances': [[1.0404009819030762, 1.243080496788025]],
  'uris': None,
  'data': None,
  'metadatas': [[None, None]],
  'embeddings': None,
}

总结

向量数据库是 RAG 中的重要组件之一,文档索引会存储在向量数据库中,随着大模型的流行,感觉向量数据库也会持续发展,进一步提高性能。

相关推荐
soulteary5 天前
福布斯 AI 50 榜单中唯一开源向量数据库:Weaviate
数据库·人工智能·开源·向量数据库·weaviate·gte
シ風箏5 天前
Milvus【部署 01】向量数据库Milvus在Linux环境下的在线+离线安装
linux·数据库·milvus·向量数据库·特征搜索
linmoo19867 天前
检索增强生成RAG系列3--RAG优化之文档处理
embedding·向量数据库·rag·pypdf·文档分块·pdfminer
Zilliz Planet1 个月前
还能报名!风靡硅谷开发者的Unstructured Data Meetup 杭州站与您6月15日见面!
milvus·向量数据库
CJ点1 个月前
AI-知识库搭建(一)腾讯云向量数据库使用
人工智能·gpt·知识库·向量数据库
OpenPie|拓数派1 个月前
2024 GIAC 全球互联网架构大会:拓数派向量数据库 PieCloudVector 架构设计与案例实践
架构·大模型·向量数据库·pieclouddb·openpie·拓数派·piecloudvector
沛沛老爹2 个月前
Milvus 简介与核心特性
数据库·数据库开发·milvus·向量数据库
m0_375599732 个月前
向量数据库:PGVector
向量数据库·pgvector