属性错误:模块“chromadb”没有属性“config”

问题描述 投票:0回答:2

所以我最近开始研究 chromabd,我遇到了这个错误: “模块‘chromadb’没有属性‘config’”

这是我的代码:

    from langchain.vectorstores import Chroma 
    from sentence_transformers import SentenceTransformer

    model = SentenceTransformer('all-MiniLM-L6-v2')

    #Sentences are encoded by calling model.encode()
    embeddings = [model.encode(text[i].page_content) for i in range(len(text))]

    presist_directory = 'db'
    vectordb =       Chroma.from_documents(documents=text,embedding=embeddings,persist_directory=presist_directory)
  1. 我已经尝试过对 chromadb 进行版本控制
  2. 尝试过这个解决方案:
    from langchain.indexes import VectorstoreIndexCreator
    from langchain.vectorstores import Chroma

    presist_directory = 'db'
    vectordb = VectorstoreIndexCreator().from_documents(
        documents=text,
        embedding=embeddings,
        persist_directory=presist_directory,
        vectorstore_cls=Chroma,
    ) 
  1. 也尝试了这个解决方案:
    import chromadb

    # Get the version of ChromaDB
    chroma_version = chromadb.__version__

    # Check if the version is 0.4 or later
    if float(chroma_version[:3]) >= 0.4:
        # Use the new configuration
        _client_settings = chromadb.config.Settings(
            chroma_db_impl="new_configuration",
            persist_directory=persist_directory,
        )
    else:
        # Use the old configuration
        _client_settings = chromadb.config.Settings(
            chroma_db_impl="duckdb+parquet",
            persist_directory=persist_directory,
        )

python nlp chatbot langchain chromadb
2个回答
1
投票

我得到了解决方案,chromadb 有兼容性问题。就我而言,我必须将版本从

0.4.6
降级到
0.4.0
。在
0.3.26
中它会抛出
'Collection' object has no attribute 'upsert'
错误,更新版本会抛出此错误。所以版本
0.4.0
似乎对我有用


0
投票

当您导入 chromadb 然后像下面这样混淆 sqlite 模块时,就会发生这种情况

__import__('pysqlite3')
import pysqlite3
sys.modules['sqlite3'] = sys.modules["pysqlite3"]

只需重新启动内核(如果您在 jupyter 中)并确保在修改 sys.modules 后导入 chromadb

© www.soinside.com 2019 - 2024. All rights reserved.