mirror of
https://github.com/hwchase17/langchain
synced 2024-11-10 01:10:59 +00:00
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:
parent
177baef3a1
commit
21d1c988a9
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user