langroid 0.59.9__py3-none-any.whl → 0.59.10__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- langroid/embedding_models/models.py +67 -2
- langroid/parsing/parse_json.py +8 -2
- {langroid-0.59.9.dist-info → langroid-0.59.10.dist-info}/METADATA +1 -1
- {langroid-0.59.9.dist-info → langroid-0.59.10.dist-info}/RECORD +6 -6
- {langroid-0.59.9.dist-info → langroid-0.59.10.dist-info}/WHEEL +0 -0
- {langroid-0.59.9.dist-info → langroid-0.59.10.dist-info}/licenses/LICENSE +0 -0
@@ -463,12 +463,12 @@ class LlamaCppServerEmbeddings(EmbeddingModel):
|
|
463
463
|
response = requests.post(self.embedding_url, json=data)
|
464
464
|
|
465
465
|
if response.status_code == 200:
|
466
|
-
embeddings = response.json()
|
466
|
+
embeddings = self._extract_embedding(response.json())
|
467
467
|
if not (
|
468
468
|
isinstance(embeddings, list) and isinstance(embeddings[0], (int, float))
|
469
469
|
):
|
470
470
|
raise ValueError(
|
471
|
-
"""Embedding endpoint has not returned the correct format.
|
471
|
+
"""Embedding endpoint has not returned the correct format.
|
472
472
|
Is the URL correct?
|
473
473
|
"""
|
474
474
|
)
|
@@ -480,6 +480,71 @@ class LlamaCppServerEmbeddings(EmbeddingModel):
|
|
480
480
|
"Failed to connect to embedding provider",
|
481
481
|
)
|
482
482
|
|
483
|
+
def _extract_embedding(
|
484
|
+
self, response_json: dict[str, Any] | list[Any]
|
485
|
+
) -> List[int | float]:
|
486
|
+
"""
|
487
|
+
Extract embedding vector from llama.cpp response.
|
488
|
+
|
489
|
+
Handles multiple response formats:
|
490
|
+
1. Native /embedding: {"embedding": [floats]}
|
491
|
+
2. Array format: [{"embedding": [floats]}]
|
492
|
+
3. Double-nested: [{"embedding": [[floats]]}]
|
493
|
+
4. OpenAI /v1/embeddings: {"data": [{"embedding": [floats]}]}
|
494
|
+
5. Nested in dict: {"embedding": [[floats]]}
|
495
|
+
|
496
|
+
Args:
|
497
|
+
response_json: The JSON response from llama.cpp server
|
498
|
+
|
499
|
+
Returns:
|
500
|
+
List of floats representing the embedding vector
|
501
|
+
|
502
|
+
Raises:
|
503
|
+
ValueError: If response format is not recognized
|
504
|
+
"""
|
505
|
+
import json
|
506
|
+
|
507
|
+
# Try native format first: {"embedding": [floats]}
|
508
|
+
if isinstance(response_json, dict) and "embedding" in response_json:
|
509
|
+
embeddings = response_json["embedding"]
|
510
|
+
# Check if it's [floats]
|
511
|
+
if isinstance(embeddings, list) and len(embeddings) > 0:
|
512
|
+
if isinstance(embeddings[0], (int, float)):
|
513
|
+
return embeddings
|
514
|
+
# Might be nested: {"embedding": [[floats]]}
|
515
|
+
if isinstance(embeddings[0], list) and len(embeddings[0]) > 0:
|
516
|
+
if isinstance(embeddings[0][0], (int, float)):
|
517
|
+
return embeddings[0]
|
518
|
+
|
519
|
+
# Try OpenAI format: {"data": [{"embedding": [floats]}]}
|
520
|
+
if isinstance(response_json, dict) and "data" in response_json:
|
521
|
+
data = response_json["data"]
|
522
|
+
if isinstance(data, list) and len(data) > 0:
|
523
|
+
if isinstance(data[0], dict) and "embedding" in data[0]:
|
524
|
+
embeddings = data[0]["embedding"]
|
525
|
+
if isinstance(embeddings, list) and len(embeddings) > 0:
|
526
|
+
if isinstance(embeddings[0], (int, float)):
|
527
|
+
return embeddings
|
528
|
+
|
529
|
+
# Try array format: [{"embedding": [floats]}] or [{"embedding": [[floats]]}]
|
530
|
+
if isinstance(response_json, list) and len(response_json) > 0:
|
531
|
+
first_item = response_json[0]
|
532
|
+
if isinstance(first_item, dict) and "embedding" in first_item:
|
533
|
+
embeddings = first_item["embedding"]
|
534
|
+
# Check if it's [floats]
|
535
|
+
if isinstance(embeddings, list) and len(embeddings) > 0:
|
536
|
+
if isinstance(embeddings[0], (int, float)):
|
537
|
+
return embeddings
|
538
|
+
# Check if it's [[floats]]
|
539
|
+
if isinstance(embeddings[0], list) and len(embeddings[0]) > 0:
|
540
|
+
if isinstance(embeddings[0][0], (int, float)):
|
541
|
+
return embeddings[0]
|
542
|
+
|
543
|
+
raise ValueError(
|
544
|
+
f"Unsupported embedding response format from {self.embedding_url}. "
|
545
|
+
f"Response: {json.dumps(response_json)[:500]}"
|
546
|
+
)
|
547
|
+
|
483
548
|
def embedding_fn(self) -> Callable[[List[str]], Embeddings]:
|
484
549
|
return EmbeddingFunctionCallable(self, self.config.batch_size)
|
485
550
|
|
langroid/parsing/parse_json.py
CHANGED
@@ -142,8 +142,14 @@ def top_level_json_field(s: str, f: str) -> Any:
|
|
142
142
|
return ""
|
143
143
|
for j in jsons:
|
144
144
|
json_data = json.loads(j)
|
145
|
-
if
|
146
|
-
|
145
|
+
if isinstance(json_data, dict):
|
146
|
+
if f in json_data:
|
147
|
+
return json_data[f]
|
148
|
+
elif isinstance(json_data, list):
|
149
|
+
# Some responses wrap candidate JSON objects in a list; scan them.
|
150
|
+
for item in json_data:
|
151
|
+
if isinstance(item, dict) and f in item:
|
152
|
+
return item[f]
|
147
153
|
|
148
154
|
return ""
|
149
155
|
|
@@ -64,7 +64,7 @@ langroid/cachedb/base.py,sha256=b104RrL1Og7K2mWFy3sWc4Er3z9zWMtY9dxQVhwnm2E,1351
|
|
64
64
|
langroid/cachedb/redis_cachedb.py,sha256=7kgnbf4b5CKsCrlL97mHWKvdvlLt8zgn7lc528jEpiE,5141
|
65
65
|
langroid/embedding_models/__init__.py,sha256=KyYxR3jDFUCfYjSuCL86qjAmrq6mXXjOT4lFNOKVj6Y,955
|
66
66
|
langroid/embedding_models/base.py,sha256=F65Vlj3RugkcntWOoKm-0b7h4T_Les6m4e7Qto_-Otg,2564
|
67
|
-
langroid/embedding_models/models.py,sha256=
|
67
|
+
langroid/embedding_models/models.py,sha256=SmUK23iX6ypisjD71ElzVizZpYmZxwQOlDpAcyXioK4,23613
|
68
68
|
langroid/embedding_models/remote_embeds.py,sha256=6_kjXByVbqhY9cGwl9R83ZcYC2km-nGieNNAo1McHaY,5151
|
69
69
|
langroid/embedding_models/protoc/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
70
70
|
langroid/embedding_models/protoc/embeddings.proto,sha256=_O-SgFpTaylQeOTgSpxhEJ7CUw7PeCQQJLaPqpPYKJg,321
|
@@ -94,7 +94,7 @@ langroid/parsing/document_parser.py,sha256=cUcp4JKS_LpsjX7OqnGBhHorDHx7FG5pvKGjR
|
|
94
94
|
langroid/parsing/file_attachment.py,sha256=f-MBRCI58XsCqJDH2HwTWwTQxLbYsDrOLgjrM1kw3XE,7350
|
95
95
|
langroid/parsing/md_parser.py,sha256=8LX9RDRWV1dZSYa-uBD8-whC_L6UYco-AQUxIuviqEk,21656
|
96
96
|
langroid/parsing/para_sentence_split.py,sha256=AJBzZojP3zpB-_IMiiHismhqcvkrVBQ3ZINoQyx_bE4,2000
|
97
|
-
langroid/parsing/parse_json.py,sha256=
|
97
|
+
langroid/parsing/parse_json.py,sha256=W_8dMD1SFohcQjbOBvRR1NrdO-F6xdhNVDmUX1nNdsY,5052
|
98
98
|
langroid/parsing/parser.py,sha256=IcwmVLlAae5LiKZ9OFhrnVOoHxcnsV7feFSHQiFfoi4,16112
|
99
99
|
langroid/parsing/pdf_utils.py,sha256=QogxU_B1N3WSLyZ9PEcJDaJoZShKs7CPQRVyF1V2DiE,3143
|
100
100
|
langroid/parsing/repo_loader.py,sha256=oB0TNifWCaqvlj7C0U76C4NZT7b94BbGkVX_-mrcH_4,30220
|
@@ -139,7 +139,7 @@ langroid/vector_store/pineconedb.py,sha256=7V0Bkt4ZrOR3V90tdXvdFmyNGuww7SFdyPq7-
|
|
139
139
|
langroid/vector_store/postgres.py,sha256=TY_VshimwFZglYgKYm7Qn1F-dCSL8GsXRTgmh7VTe9c,16110
|
140
140
|
langroid/vector_store/qdrantdb.py,sha256=mqxMOrcLAQpl0opuL8vXhdIt6ppv2zYyAvddHZoEW0Y,19184
|
141
141
|
langroid/vector_store/weaviatedb.py,sha256=BS95bxVKNYfQc9VPb85a1HlcgnXfAkgMzjydnjCgRHc,11853
|
142
|
-
langroid-0.59.
|
143
|
-
langroid-0.59.
|
144
|
-
langroid-0.59.
|
145
|
-
langroid-0.59.
|
142
|
+
langroid-0.59.10.dist-info/METADATA,sha256=LnA1YOq6VYfYsfnBONaSbzMPti5M_2IySKSNSBbdOIA,66518
|
143
|
+
langroid-0.59.10.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
144
|
+
langroid-0.59.10.dist-info/licenses/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
|
145
|
+
langroid-0.59.10.dist-info/RECORD,,
|
File without changes
|
File without changes
|