trustgraph/trustgraph-flow/trustgraph/gateway/graph_embeddings_query.py
cybermaggedon f7df2df266
Feature/librarian (#307)
* Bring QDrant up-to-date

* Tables for data from queue outputs

- Pass single Pulsar client to everything in gateway & librarian
- Pulsar listener-name support in gateway
- PDF and text load working in librarian

* Complete Cassandra schema

* Add librarian support to templates
2025-02-12 23:39:24 +00:00

40 lines
1.2 KiB
Python

from .. schema import GraphEmbeddingsRequest, GraphEmbeddingsResponse
from .. schema import graph_embeddings_request_queue
from .. schema import graph_embeddings_response_queue
from . endpoint import ServiceEndpoint
from . requestor import ServiceRequestor
from . serialize import serialize_value
class GraphEmbeddingsQueryRequestor(ServiceRequestor):
def __init__(self, pulsar_client, timeout, auth):
super(GraphEmbeddingsQueryRequestor, self).__init__(
pulsar_client=pulsar_client,
request_queue=graph_embeddings_request_queue,
response_queue=graph_embeddings_response_queue,
request_schema=GraphEmbeddingsRequest,
response_schema=GraphEmbeddingsResponse,
timeout=timeout,
)
def to_request(self, body):
limit = int(body.get("limit", 20))
return GraphEmbeddingsRequest(
vectors = body["vectors"],
limit = limit,
user = body.get("user", "trustgraph"),
collection = body.get("collection", "default"),
)
def from_response(self, message):
return {
"entities": [
serialize_value(ent) for ent in message.entities
]
}, True