community[patch]: Fixing embedchain document mapping (#18255)

- **Description:** The current embedchain implementation seems to handle
document metadata differently than done in the current implementation of
langchain and a KeyError is thrown. I would love for someone else to
test this...

---------

Co-authored-by: KKUGLER <kai.kugler@mercedes-benz.com>
Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
Co-authored-by: Deshraj Yadav <deshraj@gatech.edu>
This commit is contained in:
Kai Kugler 2024-02-29 23:54:37 +01:00 committed by GitHub
parent 040271f33a
commit df234fb171
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 3 deletions

View File

@ -65,7 +65,10 @@ class EmbedchainRetriever(BaseRetriever):
docs.append(
Document(
page_content=r["context"],
metadata={"source": r["source"], "document_id": r["document_id"]},
metadata={
"source": r["metadata"]["url"],
"document_id": r["metadata"]["doc_id"],
},
)
)
return docs

View File

@ -19,8 +19,10 @@ os.environ["OPENAI_API_KEY"] = "sk-xxxx"
context_value = [
{
"context": "this document is about John",
"source": "source#1",
"document_id": 123,
"metadata": {
"source": "source#1",
"doc_id": 123,
},
},
]