Spaces:
Runtime error
Runtime error
Update chromedb_service.py
Browse files- chromedb_service.py +9 -1
chromedb_service.py
CHANGED
|
@@ -161,9 +161,13 @@ def parse_chromadb_response(response: dict) -> list[dict]:
|
|
| 161 |
output = []
|
| 162 |
|
| 163 |
for i in range(len(response["ids"][0])):
|
|
|
|
|
|
|
|
|
|
| 164 |
output.append({
|
| 165 |
"id": response["ids"][0][i],
|
| 166 |
-
"distance":
|
|
|
|
| 167 |
"document": (
|
| 168 |
response["documents"][0][i]
|
| 169 |
if response.get("documents") else None
|
|
@@ -174,4 +178,8 @@ def parse_chromadb_response(response: dict) -> list[dict]:
|
|
| 174 |
)
|
| 175 |
})
|
| 176 |
|
|
|
|
|
|
|
|
|
|
| 177 |
return output
|
|
|
|
|
|
| 161 |
output = []
|
| 162 |
|
| 163 |
for i in range(len(response["ids"][0])):
|
| 164 |
+
distance = float(response["distances"][0][i])
|
| 165 |
+
score = round(1 / (1 + distance), 4)
|
| 166 |
+
|
| 167 |
output.append({
|
| 168 |
"id": response["ids"][0][i],
|
| 169 |
+
"distance": distance,
|
| 170 |
+
"score": score,
|
| 171 |
"document": (
|
| 172 |
response["documents"][0][i]
|
| 173 |
if response.get("documents") else None
|
|
|
|
| 178 |
)
|
| 179 |
})
|
| 180 |
|
| 181 |
+
# 🔥 TRI SERVEUR PAR SCORE (DESC)
|
| 182 |
+
output.sort(key=lambda x: x["score"], reverse=True)
|
| 183 |
+
|
| 184 |
return output
|
| 185 |
+
|