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

fixed KeyError:'metadata' Addressing issue #7 #8

Merged
merged 3 commits into from
Apr 22, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions libs/elasticsearch/langchain_elasticsearch/vectorstores.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,20 +889,20 @@ def _search(
def default_doc_builder(hit: Dict) -> Document:
return Document(
page_content=hit["_source"].get(self.query_field, ""),
metadata=hit["_source"]["metadata"],
metadata=hit["_source"].get("metadata",{}),
maxjakob marked this conversation as resolved.
Show resolved Hide resolved
)

doc_builder = doc_builder or default_doc_builder

docs_and_scores = []
for hit in response["hits"]["hits"]:
for field in fields:
if "metadata" not in hit["_source"]:
hit["_source"]["metadata"] = {}
maxjakob marked this conversation as resolved.
Show resolved Hide resolved
if field in hit["_source"] and field not in [
"metadata",
self.query_field,
]:
if "metadata" not in hit["_source"]:
hit["_source"]["metadata"] = {}
hit["_source"]["metadata"][field] = hit["_source"][field]

docs_and_scores.append(
Expand Down
Loading