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

str' object has no attribute 'page_content' #17699

Closed
4 tasks done
shobhitagnihotri69 opened this issue Feb 18, 2024 · 1 comment
Closed
4 tasks done

str' object has no attribute 'page_content' #17699

shobhitagnihotri69 opened this issue Feb 18, 2024 · 1 comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature 🔌: chroma Primarily related to ChromaDB integrations Ɑ: vector store Related to vector store module

Comments

@shobhitagnihotri69
Copy link

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.

Example Code

vectordb = Chroma.from_documents(documents=chunks
, embedding=embeddings) I am using this code to solve problem but I am not able to solve its showing ttributeError Traceback (most recent call last)
in <cell line: 1>()
----> 1 vectordb = Chroma.from_documents(documents=chunks
2 , embedding=embeddings)

1 frames
/usr/local/lib/python3.10/dist-packages/langchain_community/vectorstores/chroma.py in (.0)
774 Chroma: Chroma vectorstore.
775 """
--> 776 texts = [doc.page_content for doc in documents]
777 metadatas = [doc.metadata for doc in documents]
778 return cls.from_texts(

AttributeError: 'str' object has no attribute 'page_content'

Error Message and Stack Trace (if applicable)

No response

Description

I am using langchain to create chunks and perform vector embedding throughcgroma db , How can I change it into

System Info

I am using Mac

Copy link

dosubot bot commented Feb 18, 2024

🤖

Hey again, @shobhitagnihotri69! Great to see you back and diving into more challenges with LangChain. Let's get this sorted out for you.

Based on the error message you provided, it seems like you're trying to access the 'page_content' attribute of a string object, which does not exist. This error typically occurs when you are trying to create a Chroma vectorstore from a list of strings instead of a list of Document objects.

In LangChain, the from_documents method of the Chroma class expects a list of Document objects as input. Here's the relevant code snippet from the LangChain source code:

def from_documents(
    cls: Type[Chroma],
    documents: List[Document],
    ...
) -> Chroma:
    texts = [doc.page_content for doc in documents]
    metadatas = [doc.metadata for doc in documents]
    ...

In this code, 'doc.page_content' and 'doc.metadata' are trying to access the 'page_content' and 'metadata' attributes of each Document object in the 'documents' list. If you pass a list of strings instead of a list of Document objects to this method, you will encounter the 'AttributeError: 'str' object has no attribute 'page_content'' error.

To resolve this issue, you need to ensure that you are passing a list of Document objects to the 'from_documents' method. You can create a Document object in LangChain as follows:

from langchain_core.documents import Document

doc = Document(page_content="your text here", metadata={"your": "metadata here"})

Then, you can create a list of these Document objects and pass it to the 'from_documents' method:

documents = [doc1, doc2, ...]  # doc1, doc2, ... are Document objects
chroma = Chroma.from_documents(documents=documents, ...)

Please adjust the code to fit the specifics of your application and data structure. If you continue to encounter issues, please provide more details about your use case and the data you're working with. This will help me provide a more accurate solution.

Sources

About Dosu

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.

@dosubot dosubot bot added Ɑ: vector store Related to vector store module 🔌: chroma Primarily related to ChromaDB integrations 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature labels Feb 18, 2024
@dosubot dosubot bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label May 19, 2024
@dosubot dosubot bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 1, 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 Jun 1, 2024
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 Ɑ: vector store Related to vector store module
Projects
None yet
Development

No branches or pull requests

1 participant