Try er/redis index retrieval retry00 (#7773)

Replace this comment with:
- Description: Modified the code to return the document id from the
redis document search as metadata.
  - Issue: the issue # it fixes retrieval of id as metadata as string 
  - Tag maintainer: @rlancemartin, @eyurtsev

---------

Co-authored-by: Bagatur <baskaryan@gmail.com>
This commit is contained in:
TRY-ER 2023-07-18 23:19:50 +05:30 committed by GitHub
parent 177baef3a1
commit 21d1c988a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -319,7 +319,7 @@ class Redis(VectorStore):
base_query = (
f"{hybrid_fields}=>[KNN {k} @{self.vector_key} $vector AS vector_score]"
)
return_fields = [self.metadata_key, self.content_key, "vector_score"]
return_fields = [self.metadata_key, self.content_key, "vector_score", "id"]
return (
Query(base_query)
.return_fields(*return_fields)
@ -356,17 +356,12 @@ class Redis(VectorStore):
results = self.client.ft(self.index_name).search(redis_query, params_dict)
# Prepare document results
docs = [
(
Document(
page_content=result.content, metadata=json.loads(result.metadata)
),
float(result.vector_score),
)
for result in results.docs
]
return docs
docs_and_scores: List[Tuple[Document, float]] = []
for result in results.docs:
metadata = {**json.loads(result.metadata), "id": result.id}
doc = Document(page_content=result.content, metadata=metadata)
docs_and_scores.append((doc, float(result.vector_score)))
return docs_and_scores
@classmethod
def from_texts_return_keys(