所以我最近开始研究 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)
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,
)
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,
)
我得到了解决方案,chromadb 有兼容性问题。就我而言,我必须将版本从
0.4.6
降级到 0.4.0
。在 0.3.26
中它会抛出 'Collection' object has no attribute 'upsert'
错误,更新版本会抛出此错误。所以版本0.4.0
似乎对我有用
当您导入 chromadb 然后像下面这样混淆 sqlite 模块时,就会发生这种情况
__import__('pysqlite3')
import pysqlite3
sys.modules['sqlite3'] = sys.modules["pysqlite3"]
只需重新启动内核(如果您在 jupyter 中)并确保在修改 sys.modules 后导入 chromadb