Следующая функция работала еще несколько дней назад, но теперь выдает эту ошибку:
ValueError: Ожидается, что EmbeddingFunction._call_ будет иметь следующую подпись: odict_keys(['self', 'input']), получено odict_keys(['args', 'kwargs']). См. https://docs.trychroma. com/embeddings для получения подробной информации об интерфейсе EmbeddingFunction. Обратите внимание на недавнее изменение интерфейса EmbeddingFunction: https://docs.trychroma.com/migration#migration-to-0416---november-7-2023
Я не уверен, какие изменения необходимы для работы с этим.
` def create_chromadb(link):
embedding_function = SentenceTransformerEmbeddings(model_name = "all-MiniLM-L6-v2")
loader = TextLoader(link)
documents = loader.load()
# Split the documents into chunks (no changes needed here)
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=500)
chunks = text_splitter.split_documents(documents)
# Update for new EmbeddingFunction definition
# D is set to the type of documents (Text in this case)
D = Union[str, List[str]] # Adjust based on your document format (single string or list of strings)
embedding_function: EmbeddingFunction[D] = embedding_function
# Initialize Chroma with the embedding function and persist the database
db = Chroma.from_documents(chunks, embedding_function, ids=None, collection_name = "langchain", persist_directory = "./chroma_db")
db.persist()
print(f"Saved {len(chunks)} chunks")
return db`
docs.trychroma.com/migration#migration-to-0416---ноябрь-7-2023






Я немного модифицирую ваш код, используя HuggingFaceEmbeddings вместо SentenceTransformerEmbeddings.
from langchain_community.embeddings import HuggingFaceEmbeddings
embedding = HuggingFaceEmbeddings(
model_name = "sentence-transformers/all-MiniLM-L6-v2")
from langchain_community.vectorstores import Chroma
db = Chroma.from_documents(
documents=chunks,
embedding=embedding,
persist_directory = "/tmp/chroma_db"
)
db.persist()