向量数据库的使用

向量数据库

向量数据库是一种专门用于存储、管理和查询高维向量数据的数据库系统。随着人工智能和机器学习的广泛应用,向量数据库在处理非结构化数据(如文本、图像、音频和视频等)的任务中变得越来越重要。本文将介绍快速使用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 中的重要组件之一,文档索引会存储在向量数据库中,随着大模型的流行,感觉向量数据库也会持续发展,进一步提高性能。

相关推荐
_张一凡10 天前
通往RAG之路(五):主流向量数据库全景解析与选型指南
pinecone·milvus·向量数据库·chroma·qdrant·rag系统搭建
虎妞050013 天前
向量数据库选型指南:Milvus vs Chroma vs Weaviate
milvus·向量数据库·chroma·rag·weaviate
SXJR13 天前
使用docker 部署向量数据库Milvus
数据库·docker·容器·milvus·向量数据库
codefan※14 天前
Reranker 模型实战:让 RAG 检索精度再提升 20%
大模型·llm·向量数据库·rag
AllData公司负责人16 天前
大模型赋能AllData数据中台,系列升级|通过联合智谱大模型与BiSheng开源项目,建设企业大模型应用开发平台,支持知识库向量检索!
大数据·数据结构·数据库·算法·大模型·向量数据库·智谱ai
摸鱼同学16 天前
04-Embedding 和向量数据库:让机器真正理解语义
ai·chatgpt·embedding·agent·向量数据库
尽兴-16 天前
2.3 向量数据库:FAISS、Chroma、Milvus、Pinecone、Qdrant
pinecone·milvus·faiss·向量数据库·chroma·qdrant
codefan※21 天前
RAG 加速指南:Faiss / Milvus / Qdrant 向量库选型与调优
知识图谱·milvus·faiss·向量数据库·rag·qdrant
填满你的记忆21 天前
《为什么 MySQL 不适合做 AI 检索?》
数据库·人工智能·mysql·ai·向量数据库
小何code22 天前
人工智能【第52篇】RAG系统实战:检索增强生成技术详解
embedding·向量数据库·rag·检索增强生成·llm应用