ray-embedding 0.9.9__py3-none-any.whl → 0.10.0__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.
Potentially problematic release.
This version of ray-embedding might be problematic. Click here for more details.
- ray_embedding/embedding_model.py +31 -5
- {ray_embedding-0.9.9.dist-info → ray_embedding-0.10.0.dist-info}/METADATA +1 -1
- ray_embedding-0.10.0.dist-info/RECORD +8 -0
- {ray_embedding-0.9.9.dist-info → ray_embedding-0.10.0.dist-info}/WHEEL +1 -1
- ray_embedding-0.9.9.dist-info/RECORD +0 -8
- {ray_embedding-0.9.9.dist-info → ray_embedding-0.10.0.dist-info}/top_level.txt +0 -0
ray_embedding/embedding_model.py
CHANGED
|
@@ -69,25 +69,51 @@ class EmbeddingModel:
|
|
|
69
69
|
assert request.model == self.served_model_name, (
|
|
70
70
|
f"Model '{request.model}' is not supported. Use '{self.served_model_name}' instead."
|
|
71
71
|
)
|
|
72
|
-
|
|
72
|
+
|
|
73
|
+
if isinstance(request.input, str):
|
|
74
|
+
request.input = [request.input]
|
|
75
|
+
|
|
76
|
+
truncate_dim = request.dimensions or self.matryoshka_dim
|
|
77
|
+
|
|
78
|
+
# Compute embeddings and convert to a PyTorch tensor on the GPU
|
|
79
|
+
embeddings = self.embedding_model.encode(
|
|
80
|
+
request.input, convert_to_tensor=True, normalize_embeddings=True
|
|
81
|
+
).to(self.torch_device)
|
|
82
|
+
|
|
83
|
+
if truncate_dim is not None:
|
|
84
|
+
# Truncate and re-normalize the embeddings
|
|
85
|
+
embeddings = embeddings[:, :truncate_dim]
|
|
86
|
+
embeddings = embeddings / torch.norm(embeddings, dim=1, keepdim=True)
|
|
87
|
+
|
|
88
|
+
# Move all embeddings to CPU at once before conversion
|
|
89
|
+
embeddings = embeddings.cpu().tolist()
|
|
90
|
+
|
|
91
|
+
# Convert embeddings to list format for response
|
|
92
|
+
response_data = [
|
|
93
|
+
{"index": idx, "embedding": emb}
|
|
94
|
+
for idx, emb in enumerate(embeddings)
|
|
95
|
+
]
|
|
96
|
+
return EmbeddingResponse(object="list", data=response_data, model=request.model)
|
|
97
|
+
|
|
73
98
|
except Exception as e:
|
|
74
99
|
self.logger.error(e)
|
|
75
100
|
raise HTTPException(status_code=500, detail=str(e))
|
|
76
101
|
|
|
77
102
|
@serve.batch(max_batch_size=8, batch_wait_timeout_s=0.25)
|
|
78
103
|
async def __create_embeddings_batch(self, requests_batch: List[EmbeddingRequest]) -> List[EmbeddingResponse]:
|
|
79
|
-
self_0 = self[0] if isinstance(self, list) else self
|
|
104
|
+
self_0 = self[0] if isinstance(self, list) else self # Ray also passes an array of self refs; just take the first one
|
|
105
|
+
embedding_model, matryoshka_dim, torch_device = self_0.embedding_model, self_0.matryoshka_dim, self_0.torch_device
|
|
80
106
|
|
|
81
107
|
inputs, truncate_dims, num_inputs_list = [], [], []
|
|
82
108
|
for request in requests_batch:
|
|
83
109
|
input_text = request.input if isinstance(request.input, list) else [request.input] # Can be a list of texts
|
|
84
110
|
inputs.extend(input_text)
|
|
85
111
|
num_inputs_list.append(len(input_text))
|
|
86
|
-
truncate_dims.append(request.dimensions or
|
|
112
|
+
truncate_dims.append(request.dimensions or matryoshka_dim)
|
|
87
113
|
|
|
88
|
-
embeddings =
|
|
114
|
+
embeddings = embedding_model.encode(
|
|
89
115
|
inputs, convert_to_tensor=True, normalize_embeddings=True, show_progress_bar=False,
|
|
90
|
-
).to(
|
|
116
|
+
).to(torch_device)
|
|
91
117
|
|
|
92
118
|
model_name = requests_batch[0].model
|
|
93
119
|
truncate_needed = any(dim is not None for dim in truncate_dims)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
ray_embedding/__init__.py,sha256=OYJT0rVaaGzY613JqgfktsCgroDnBkGOHxR2FE9UtRU,49
|
|
2
|
+
ray_embedding/deploy.py,sha256=oqOhMxS5UyZ4oGhfpL7kqvrxLO8QW41sF_FHbNSJe-w,1858
|
|
3
|
+
ray_embedding/dto.py,sha256=e91ejZbM_NB9WTjF1YnfuV71cajYIh0vOX8oV_g2OwM,595
|
|
4
|
+
ray_embedding/embedding_model.py,sha256=cyGH7CZRCAV50T51aTAxTSRCU0haCV_mX42tyhmFa6U,7007
|
|
5
|
+
ray_embedding-0.10.0.dist-info/METADATA,sha256=8uU8yj2bnbxZPlL1WEaU0V6ioi0We6rcUUzTGd62yTk,605
|
|
6
|
+
ray_embedding-0.10.0.dist-info/WHEEL,sha256=GHB6lJx2juba1wDgXDNlMTyM13ckjBMKf-OnwgKOCtA,91
|
|
7
|
+
ray_embedding-0.10.0.dist-info/top_level.txt,sha256=ziCblpJq1YsrryshFqxTRuRMgNuO1_tgvAAkGShATNA,14
|
|
8
|
+
ray_embedding-0.10.0.dist-info/RECORD,,
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
ray_embedding/__init__.py,sha256=OYJT0rVaaGzY613JqgfktsCgroDnBkGOHxR2FE9UtRU,49
|
|
2
|
-
ray_embedding/deploy.py,sha256=oqOhMxS5UyZ4oGhfpL7kqvrxLO8QW41sF_FHbNSJe-w,1858
|
|
3
|
-
ray_embedding/dto.py,sha256=e91ejZbM_NB9WTjF1YnfuV71cajYIh0vOX8oV_g2OwM,595
|
|
4
|
-
ray_embedding/embedding_model.py,sha256=PBBuntLrJiwstD9AbD2n_ElU7rYZAYK0fMSESkMsFTU,5797
|
|
5
|
-
ray_embedding-0.9.9.dist-info/METADATA,sha256=XRtQFNU7mhhSXFZF1YMyIII3zW9PfTXkiUN6AEHVAkA,604
|
|
6
|
-
ray_embedding-0.9.9.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
|
7
|
-
ray_embedding-0.9.9.dist-info/top_level.txt,sha256=ziCblpJq1YsrryshFqxTRuRMgNuO1_tgvAAkGShATNA,14
|
|
8
|
-
ray_embedding-0.9.9.dist-info/RECORD,,
|
|
File without changes
|