mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-04-27 01:16:22 +02:00
- Keeps processing in different flows separate so that data can go to different stores / collections etc. - Potentially supports different processing flows - Tidies the processing API with common base-classes for e.g. LLMs, and automatic configuration of 'clients' to use the right queue names in a flow
50 lines
1 KiB
Python
50 lines
1 KiB
Python
|
|
"""
|
|
Document embeddings store base class
|
|
"""
|
|
|
|
from .. schema import DocumentEmbeddings
|
|
from .. base import FlowProcessor, ConsumerSpec
|
|
from .. exceptions import TooManyRequests
|
|
|
|
default_ident = "document-embeddings-write"
|
|
|
|
class DocumentEmbeddingsStoreService(FlowProcessor):
|
|
|
|
def __init__(self, **params):
|
|
|
|
id = params.get("id")
|
|
|
|
super(DocumentEmbeddingsStoreService, self).__init__(
|
|
**params | { "id": id }
|
|
)
|
|
|
|
self.register_specification(
|
|
ConsumerSpec(
|
|
name = "input",
|
|
schema = DocumentEmbeddings,
|
|
handler = self.on_message
|
|
)
|
|
)
|
|
|
|
async def on_message(self, msg, consumer, flow):
|
|
|
|
try:
|
|
|
|
request = msg.value()
|
|
|
|
await self.store_document_embeddings(request)
|
|
|
|
except TooManyRequests as e:
|
|
raise e
|
|
|
|
except Exception as e:
|
|
|
|
print(f"Exception: {e}")
|
|
raise e
|
|
|
|
@staticmethod
|
|
def add_args(parser):
|
|
|
|
FlowProcessor.add_args(parser)
|
|
|