mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-04-26 00:46:22 +02:00
Batch embeddings (#668)
Base Service (trustgraph-base/trustgraph/base/embeddings_service.py): - Changed on_request to use request.texts FastEmbed Processor (trustgraph-flow/trustgraph/embeddings/fastembed/processor.py): - on_embeddings(texts, model=None) now processes full batch efficiently - Returns [[v.tolist()] for v in vecs] - list of vector sets Ollama Processor (trustgraph-flow/trustgraph/embeddings/ollama/processor.py): - on_embeddings(texts, model=None) passes list directly to Ollama - Returns [[embedding] for embedding in embeds.embeddings] EmbeddingsClient (trustgraph-base/trustgraph/base/embeddings_client.py): - embed(texts, timeout=300) accepts list of texts Tests Updated: - test_fastembed_dynamic_model.py - 4 tests updated for new interface - test_ollama_dynamic_model.py - 4 tests updated for new interface Updated CLI, SDK and APIs
This commit is contained in:
parent
3bf8a65409
commit
0a2ce47a88
16 changed files with 785 additions and 79 deletions
|
|
@ -3,11 +3,11 @@ from . request_response_spec import RequestResponse, RequestResponseSpec
|
|||
from .. schema import EmbeddingsRequest, EmbeddingsResponse
|
||||
|
||||
class EmbeddingsClient(RequestResponse):
|
||||
async def embed(self, text, timeout=30):
|
||||
async def embed(self, texts, timeout=300):
|
||||
|
||||
resp = await self.request(
|
||||
EmbeddingsRequest(
|
||||
text = text
|
||||
texts = texts
|
||||
),
|
||||
timeout=timeout
|
||||
)
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ class EmbeddingsService(FlowProcessor):
|
|||
|
||||
# Pass model from request if specified (non-empty), otherwise use default
|
||||
model = flow("model")
|
||||
vectors = await self.on_embeddings(request.text, model=model)
|
||||
vectors = await self.on_embeddings(request.texts, model=model)
|
||||
|
||||
await flow("response").send(
|
||||
EmbeddingsResponse(
|
||||
|
|
@ -94,7 +94,7 @@ class EmbeddingsService(FlowProcessor):
|
|||
type = "embeddings-error",
|
||||
message = str(e),
|
||||
),
|
||||
vectors=None,
|
||||
vectors=[],
|
||||
),
|
||||
properties={"id": id}
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue