Spaces:
Sleeping
Sleeping
住所処理の埋め込み機能を改善し、リクエストを2048件ずつ分割して処理するように変更。全てのレスポンスを統合して返すように修正しました。
Browse files
app.py
CHANGED
@@ -221,23 +221,28 @@ class InferenceEndpointError(Exception):
|
|
221 |
|
222 |
def embed_via_multilingual_e5_large(query_addresses):
|
223 |
headers = {
|
224 |
-
"Accept"
|
225 |
"Authorization": f"Bearer {HUGGING_FACE_TOKEN}",
|
226 |
-
"Content-Type": "application/json"
|
227 |
}
|
228 |
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
|
|
|
|
|
|
|
|
|
|
241 |
|
242 |
def search_via_milvus(query_vector, top_k, collection_name, thresh=0.0):
|
243 |
search_params = {"metric_type": "COSINE", "params": {"nprobe": 10}} # MiniLM系はCOSINE推奨
|
|
|
221 |
|
222 |
def embed_via_multilingual_e5_large(query_addresses):
|
223 |
headers = {
|
224 |
+
"Accept": "application/json",
|
225 |
"Authorization": f"Bearer {HUGGING_FACE_TOKEN}",
|
226 |
+
"Content-Type": "application/json"
|
227 |
}
|
228 |
|
229 |
+
all_responses = []
|
230 |
+
for i in range(0, len(query_addresses), 2048):
|
231 |
+
chunk = query_addresses[i:i + 2048]
|
232 |
+
response = requests.post(EMBEDDING_MODEL_ENDPOINT, headers=headers, json={"inputs": chunk})
|
233 |
+
response_json = response.json()
|
234 |
+
|
235 |
+
if 'error' in response_json:
|
236 |
+
if response_json['error'] == 'Bad Request: Invalid state':
|
237 |
+
raise InferenceEndpointError(InferenceEndpointErrorCode.INVALID_STATE, "Bad Request: Invalid state")
|
238 |
+
elif response_json['error'] == '503 Service Unavailable':
|
239 |
+
raise InferenceEndpointError(InferenceEndpointErrorCode.SERVICE_UNAVAILABLE, "Service Unavailable")
|
240 |
+
else:
|
241 |
+
raise InferenceEndpointError(InferenceEndpointErrorCode.UNKNOWN_ERROR, response_json['error'])
|
242 |
+
|
243 |
+
all_responses.extend(response_json)
|
244 |
+
|
245 |
+
return all_responses
|
246 |
|
247 |
def search_via_milvus(query_vector, top_k, collection_name, thresh=0.0):
|
248 |
search_params = {"metric_type": "COSINE", "params": {"nprobe": 10}} # MiniLM系はCOSINE推奨
|