Skip to content

Commit 833982a

Browse files
fix(docstore): preserve retrieval ranking order in lancedb get() (#745)
1 parent ddb5187 commit 833982a

File tree

1 file changed

+7
-4
lines changed
  • libs/kotaemon/kotaemon/storages/docstores

1 file changed

+7
-4
lines changed

libs/kotaemon/kotaemon/storages/docstores/lancedb.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,17 @@ def get(self, ids: Union[List[str], str]) -> List[Document]:
113113
)
114114
except (ValueError, FileNotFoundError):
115115
docs = []
116-
return [
117-
Document(
118-
id_=doc["id"],
116+
117+
# return the documents using the order of original ids (which were ordered by score)
118+
doc_dict = {
119+
doc["id"]: Document(
120+
d_=doc["id"],
119121
text=doc["text"] if doc["text"] else "<empty>",
120122
metadata=json.loads(doc["attributes"]),
121123
)
122124
for doc in docs
123-
]
125+
}
126+
return [doc_dict[_id] for _id in ids if _id in doc_dict]
124127

125128
def delete(self, ids: Union[List[str], str], refresh_indices: bool = True):
126129
"""Delete document by id"""

0 commit comments

Comments
 (0)