llama_index [Bug]: index.ref_doc_info 与 chromadb 不兼容

bkhjykvo  于 2个月前  发布在  其他
关注(0)|答案(6)|浏览(50)

错误描述

使用index.ref_doc_info在chromadb中无法正常工作,会出现错误。

版本

0.10.41

重现步骤

启动index.ref_doc_info

相关日志/回溯信息

**none**
slmsl1lt

slmsl1lt1#

嘿,@Rust-Ninja-Sabi!我在这里帮助你解决这个仓库中的任何错误、问题或贡献。在等待人工维护者时,我会协助你。
index.ref_doc_info 在 0.10.41 版本中无法与 chromadb 一起使用,因为 ChromaVectorStore 类没有名为 ref_doc_info 的属性或方法。该类旨在处理与节点及其嵌入相关的操作,但不包括与 ref_doc_info1(https://github.com/run-llama/llama_index/blob/main/llama-index-legacy/llama_index/legacy/vector_stores/chroma.py)2(https://github.com/run-llama/llama_index/blob/main/llama-index-integrations/vector_stores/llama-index-vector-stores-chroma/llama_index/vector_stores/chroma/base.py) 相关的任何功能。
遇到的具体错误信息是:

raise NotImplementedError(
    "Vector store integrations that store text in the vector store are "
    "not supported by ref_doc_info yet."
)

对于管理不支持 ref_doc_info 的矢量存储中的文档引用和元数据,你可以遵循推荐的做法,例如将节点存储在文档存储中并确保正确管理元数据。

  • 要继续与 @dosu 对话,请提及 @dosu。*
00jrzges

00jrzges2#

当它与Chromadb一起工作时,何时才能生效?我使用llama索引来为所有可用的存储提供一个API。但是据我所知,文档管理功能在Chromadb中不可用。它是否适用于任何矢量数据库?谢谢。

erhoui1w

erhoui1w3#

文档管理适用于chromadb矢量数据库。提供的代码演示了如何在ChromaVectorStore中使用chromadb创建、添加、删除和查询文档。
以下是如何设置和使用ChromaVectorStore的示例:

import chromadb
from llama_index.vector_stores.chroma import ChromaVectorStore

# Create a Chroma client and collection
chroma_client = chromadb.EphemeralClient()
chroma_collection = chroma_client.create_collection("example_collection")

# Set up the ChromaVectorStore and StorageContext
vector_store = ChromaVectorStore(chroma_collection=chroma_collection)

# Example of adding nodes
nodes = [...]  # List of BaseNode instances with embeddings
vector_store.add(nodes)

# Example of querying nodes
query = VectorStoreQuery(query_embedding=[...], similarity_top_k=5)
result = vector_store.query(query)

# Example of deleting nodes
vector_store.delete_nodes(node_ids=["node_id_1", "node_id_2"])

此外,llama_index库中的ChromaReader类允许您从现有的持久化Chroma集合中检索文档。以下是如何使用ChromaReader的示例:

from llama_index.legacy.readers.chroma import ChromaReader

# Initialize the ChromaReader
chroma_reader = ChromaReader(
    collection_name="example_collection",
    persist_directory="/path/to/persisted/collection"
)

# Load data from the collection
documents = chroma_reader.load_data(query_embedding=[...], limit=10)

对于持久存储,您可以使用PersistentClient来管理您的Chroma集合。以下是一个示例:

from typing import Optional
from llama_index.vector_stores.chroma import ChromaVectorStore
import chromadb

def get_vector_store(docset_id) -> Optional[ChromaVectorStore]:
    db = chromadb.PersistentClient(path="/path/to/persisted/collection")
    chroma_collection = db.get_or_create_collection(docset_id)
    return ChromaVectorStore(
        chroma_collection=chroma_collection, embed_model=EMBEDDINGS
    )

这种设置确保了您使用chromadb进行的文档管理既灵活又具有持久性。

  • 要继续与Dosu交谈,请提及@dosu。*
uhry853o

uhry853o4#

@dosu vector_store.get_notes() is not implemented. Can you show me the query to get all nodes? Thanks.

eulz3vhy

eulz3vhy5#

要查询和检索 ChromaVectorStore 中的所有节点,您可以使用带有空查询的 query 方法。以下是一个示例:

import chromadb
from llama_index.vector_stores.chroma import ChromaVectorStore
from llama_index.core.vector_stores.types import VectorStoreQuery

Create a Chroma client and collection

chroma_client = chromadb.Client()
collection = chroma_client.get_or_create_collection("example_collection")

Set up the ChromaVectorStore

vector_store = ChromaVectorStore.from_collection(collection)

Retrieve all nodes

query = VectorStoreQuery(query_embedding=[], similarity_top_k=0)
all_nodes_result = vector_store.query(query)

all_nodes_result.nodes will contain the list of all nodes in the collection

print(all_nodes_result.nodes)

这段代码将通过调用带有空查询嵌入和 similarity_top_k 设置为 0 的 query 方法来从 ChromaVectorStore 中检索所有节点。query 方法将返回一个包含集合 1(https://github.com/run-llama/llama_index/blob/main/llama-index-integrations/vector_stores/llama-index-vector-stores-chroma/llama_index/vector_stores/chroma/base.py)2(https://github.com/run-llama/llama_index/blob/main/llama-index-legacy/llama_index/legacy/vector_stores/chroma.py)3(https://github.com/run-llama/llama_index/blob/main/llama-index-integrations/vector_stores/llama-index-vector-stores-chroma/tests/test_chromadb.py) 中所有节点的 VectorStoreQueryResult 对象。

  • 要继续与 Dosu 交谈,请提及 @dosu。*
monwx1rj

monwx1rj6#

@Rust-Ninja-Sabi 这是正确的。ref_doc_info 依赖于有一个文档存储,但大多数向量数据库禁用文档存储,因为它们将所有节点存储在向量数据库中(简化存储)。
我建议使用带有附加向量存储和文档存储的摄取管道。

相关问题