如何为LangChain向量存储提供嵌入函数?解决ChromaDB报错
问题解决:ChromaDB调用add_texts时报错
ValueError: You must provide embeddings or a function to compute them 错误原因
- 初始化Chroma向量存储实例时未指定嵌入模型,导致Chroma无法确定文本嵌入的生成方式
add_texts方法不支持embedding_function参数,该参数需在Chroma初始化阶段传入
修正后的代码
from langchain.embeddings.openai import OpenAIEmbeddings from langchain.vectorstores import Chroma # 初始化OpenAI嵌入模型 embeddings = OpenAIEmbeddings() # 创建Chroma实例时传入嵌入模型 db = Chroma(embedding_function=embeddings) texts = [ """ One of the most common ways to store and search over unstructured data is to embed it and store the resulting embedding vectors, and then at query time to embed the unstructured query and retrieve the embedding vectors that are 'most similar' to the embedded query. A vector store takes care of storing embedded data and performing vector search for you. """, """ Today's applications are required to be highly responsive and always online. To achieve low latency and high availability, instances of these applications need to be deployed in datacenters that are close to their users. Applications need to respond in real time to large changes in usage at peak hours, store ever increasing volumes of data, and make this data available to users in milliseconds. """ ] # 直接调用add_texts添加文本 db.add_texts(texts)
内容的提问来源于stack exchange,提问作者Igor L.
相关产品推荐
相关产品推荐

