mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-22 03:31:02 +02:00
Updated query/store
This commit is contained in:
parent
94f692ff93
commit
4943b87f7a
8 changed files with 162 additions and 148 deletions
|
|
@ -20,4 +20,7 @@ from . prompt_client import PromptClientSpec
|
|||
from . triples_store_service import TriplesStoreService
|
||||
from . graph_embeddings_store_service import GraphEmbeddingsStoreService
|
||||
from . document_embeddings_store_service import DocumentEmbeddingsStoreService
|
||||
from . triples_query_service import TriplesQueryService
|
||||
from . graph_embeddings_query_service import GraphEmbeddingsQueryService
|
||||
from . document_embeddings_query_service import DocumentEmbeddingsQueryService
|
||||
|
||||
|
|
|
|||
84
trustgraph-base/trustgraph/base/document_embeddings_query_service.py
Executable file
84
trustgraph-base/trustgraph/base/document_embeddings_query_service.py
Executable file
|
|
@ -0,0 +1,84 @@
|
|||
|
||||
"""
|
||||
Document embeddings query service. Input is vectors. Output is list of
|
||||
embeddings.
|
||||
"""
|
||||
|
||||
from .. schema import DocumentEmbeddingsRequest, DocumentEmbeddingsResponse
|
||||
from .. schema import Error, Value
|
||||
|
||||
from . flow_processor import FlowProcessor
|
||||
from . consumer_spec import ConsumerSpec
|
||||
from . producer_spec import ProducerSpec
|
||||
|
||||
default_ident = "ge-query"
|
||||
|
||||
class DocumentEmbeddingsQueryService(FlowProcessor):
|
||||
|
||||
def __init__(self, **params):
|
||||
|
||||
id = params.get("id")
|
||||
|
||||
super(DocumentEmbeddingsQueryService, self).__init__(
|
||||
**params | { "id": id }
|
||||
)
|
||||
|
||||
self.register_specification(
|
||||
ConsumerSpec(
|
||||
name = "request",
|
||||
schema = DocumentEmbeddingsRequest,
|
||||
handler = self.on_message
|
||||
)
|
||||
)
|
||||
|
||||
self.register_specification(
|
||||
ProducerSpec(
|
||||
name = "response",
|
||||
schema = DocumentEmbeddingsResponse,
|
||||
)
|
||||
)
|
||||
|
||||
async def on_message(self, msg, consumer, flow):
|
||||
|
||||
try:
|
||||
|
||||
request = msg.value()
|
||||
|
||||
# Sender-produced ID
|
||||
id = msg.properties()["id"]
|
||||
|
||||
print(f"Handling input {id}...", flush=True)
|
||||
|
||||
entities = self.query_document_embeddings(request)
|
||||
|
||||
print("Send response...", flush=True)
|
||||
r = DocumentEmbeddingsResponse(entities=entities, error=None)
|
||||
await flow("response").send(r, properties={"id": id})
|
||||
|
||||
print("Done.", flush=True)
|
||||
|
||||
except Exception as e:
|
||||
|
||||
print(f"Exception: {e}")
|
||||
|
||||
print("Send error response...", flush=True)
|
||||
|
||||
r = DocumentEmbeddingsResponse(
|
||||
error=Error(
|
||||
type = "document-embeddings-query-error",
|
||||
message = str(e),
|
||||
),
|
||||
response=None,
|
||||
)
|
||||
|
||||
await flow("response").send(r, properties={"id": id})
|
||||
|
||||
@staticmethod
|
||||
def add_args(parser):
|
||||
|
||||
FlowProcessor.add_args(parser)
|
||||
|
||||
def run():
|
||||
|
||||
Processor.launch(default_ident, __doc__)
|
||||
|
||||
|
|
@ -4,11 +4,12 @@ Graph embeddings query service. Input is vectors. Output is list of
|
|||
embeddings.
|
||||
"""
|
||||
|
||||
from .... schema import GraphEmbeddingsRequest, GraphEmbeddingsResponse
|
||||
from .... schema import Error, Value
|
||||
from .. schema import GraphEmbeddingsRequest, GraphEmbeddingsResponse
|
||||
from .. schema import Error, Value
|
||||
|
||||
from .... base import FlowProcessor, GraphEmbeddingsQueryService, ConsumerSpec
|
||||
from .... base import ProducerSpec
|
||||
from . flow_processor import FlowProcessor
|
||||
from . consumer_spec import ConsumerSpec
|
||||
from . producer_spec import ProducerSpec
|
||||
|
||||
default_ident = "ge-query"
|
||||
|
||||
|
|
@ -75,7 +76,7 @@ class GraphEmbeddingsQueryService(FlowProcessor):
|
|||
@staticmethod
|
||||
def add_args(parser):
|
||||
|
||||
GraphEmbeddingsQueryService.add_args(parser)
|
||||
FlowProcessor.add_args(parser)
|
||||
|
||||
def run():
|
||||
|
||||
|
|
|
|||
|
|
@ -4,11 +4,12 @@ Triples query service. Input is a (s, p, o) triple, some values may be
|
|||
null. Output is a list of triples.
|
||||
"""
|
||||
|
||||
from .... schema import TriplesQueryRequest, TriplesQueryResponse, Error
|
||||
from .... schema import Value, Triple
|
||||
from .. schema import TriplesQueryRequest, TriplesQueryResponse, Error
|
||||
from .. schema import Value, Triple
|
||||
|
||||
from .... base import FlowProcessor, TriplesQueryService, ConsumerSpec
|
||||
from .... base import ProducerSpec
|
||||
from . flow_processor import FlowProcessor
|
||||
from . consumer_spec import ConsumerSpec
|
||||
from . producer_spec import ProducerSpec
|
||||
|
||||
default_ident = "triples-query"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue