Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple values for keyword argument 'embedding_function' #13050

Closed
2 of 14 tasks
95 opened this issue Nov 8, 2023 · 4 comments
Closed
2 of 14 tasks

Multiple values for keyword argument 'embedding_function' #13050

95 opened this issue Nov 8, 2023 · 4 comments
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature 🔌: chroma Primarily related to ChromaDB integrations Ɑ: embeddings Related to text embedding models module Ɑ: vector store Related to vector store module

Comments

@95
Copy link

95 commented Nov 8, 2023

System Info

Running on google colab.
Everything was working up until today, which makes me think it's openAi update-related.

Versions:
Requirement already satisfied: langchain in /usr/local/lib/python3.10/dist-packages (0.0.331)
Requirement already satisfied: chromadb in /usr/local/lib/python3.10/dist-packages (0.4.16)
Openai version pinned to 0.28.1 as @hwchase17 recommended prior -- which had fixed my embeddings issue.

Who can help?

@hwchase17 @agola11

Information

  • The official example notebooks/scripts
  • My own modified scripts

Related Components

  • LLMs/Chat Models
  • Embedding Models
  • Prompts / Prompt Templates / Prompt Selectors
  • Output Parsers
  • Document Loaders
  • Vector Stores / Retrievers
  • Memory
  • Agents / Agent Executors
  • Tools / Toolkits
  • Chains
  • Callbacks/Tracing
  • Async

Reproduction

from langchain.vectorstores import Chroma
from langchain.embeddings import OpenAIEmbeddings

embeddings = OpenAIEmbeddings()
vectorstore = Chroma.from_documents(documents=splits, embedding_function=embeddings, persist_directory='/content/wtf')
vectorstore.persist()
retriever = vectorstore.as_retriever()

TypeError Traceback (most recent call last)
in <cell line: 7>()
5
6 embeddings = OpenAIEmbeddings()
----> 7 vectorstore = Chroma.from_documents(documents=splits, embedding_function=embeddings, persist_directory='/content/wtf')
8 vectorstore.persist()
9 retriever = vectorstore.as_retriever()

1 frames
/usr/local/lib/python3.10/dist-packages/langchain/vectorstores/chroma.py in from_texts(cls, texts, embedding, metadatas, ids, collection_name, persist_directory, client_settings, client, collection_metadata, **kwargs)
618 Chroma: Chroma vectorstore.
619 """
--> 620 chroma_collection = cls(
621 collection_name=collection_name,
622 embedding_function=embedding,

TypeError: langchain.vectorstores.chroma.Chroma() got multiple values for keyword argument 'embedding_function'

Expected behavior

It should run without an error and correctly embed the document splits, outputting the data in the persist directory.

Copy link

dosubot bot commented Nov 8, 2023

🤖

Hello @95!

I'm Dosu, a bot here to assist you with LangChain. I can help you troubleshoot bugs, answer your questions, and guide you on how to contribute to our repository. While we wait for a human maintainer to join us, feel free to ask me anything.

I'm currently reviewing your issue and will get back to you with a full response as soon as possible.

@dosubot dosubot bot added Ɑ: embeddings Related to text embedding models module Ɑ: vector store Related to vector store module 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature 🔌: chroma Primarily related to ChromaDB integrations labels Nov 8, 2023
Copy link

dosubot bot commented Nov 8, 2023

🤖

Based on the error message you're receiving, it seems like there might be a conflict with the embedding_function argument you're passing to the Chroma.from_documents() method. The error message suggests that the embedding_function argument is being provided multiple times, which is causing the TypeError.

Looking at the signature of the Chroma.from_documents() method:

@classmethod
def from_documents(
    cls: Type[Chroma],
    documents: List[Document],
    embedding: Optional[Embeddings] = None,
    ids: Optional[List[str]] = None,
    collection_name: str = _LANGCHAIN_DEFAULT_COLLECTION_NAME,
    persist_directory: Optional[str] = None,
    client_settings: Optional[chromadb.config.Settings] = None,
    client: Optional[chromadb.Client] = None,
    collection_metadata: Optional[Dict] = None,
    **kwargs: Any,
) -> Chroma:

It appears that the embedding argument should be used instead of embedding_function. So, your code should look like this:

from langchain.vectorstores import Chroma
from langchain.embeddings import OpenAIEmbeddings

embeddings = OpenAIEmbeddings()
vectorstore = Chroma.from_documents(documents=splits, embedding=embeddings, persist_directory='/content/wtf')
vectorstore.persist()
retriever = vectorstore.as_retriever()

Please try this modification and let me know if it resolves your issue. If not, please provide any additional error messages or information that could help diagnose the problem.

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

Copy link

dosubot bot commented Feb 7, 2024

Hi, @95,

I'm helping the LangChain team manage their backlog and am marking this issue as stale. From what I understand, the issue involved a TypeError in the Chroma class of the langchain library, specifically related to the embedding_function keyword argument. Dosu-bot provided a detailed response with code snippets and references to relevant sources, suggesting a modification to the code to resolve the issue. User reactions were also captured, indicating that the issue has been addressed.

Could you please confirm if this issue is still relevant to the latest version of the LangChain repository? If it is, please let the LangChain team know by commenting on the issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days. Thank you!

@dosubot dosubot bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Feb 7, 2024
@dosubot dosubot bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 14, 2024
@dosubot dosubot bot removed the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Feb 14, 2024
@shawnesquivel
Copy link

shawnesquivel commented Apr 5, 2024

@95 I found the error.

if you use Chroma.from_documents you should use embedding

from langchain_community.vectorstores import Chroma
    embeddings = OpenAIEmbeddings()

    db = Chroma.from_documents(
        documents=docs,
        embedding=embeddings)

if you use Chroma you should use embedding_function

from langchain_community.vectorstores import Chroma
    embeddings = OpenAIEmbeddings()

    db = Chroma(
        persist_directory="some-directory",
        embeddings_function=embeddings)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature 🔌: chroma Primarily related to ChromaDB integrations Ɑ: embeddings Related to text embedding models module Ɑ: vector store Related to vector store module
Projects
None yet
Development

No branches or pull requests

2 participants