trustgraph/trustgraph-base/trustgraph/base/document_embeddings_store_service.py
CyberRaccoonTeam a1c95f9745 feat: add type hints to all public functions in trustgraph/base
Add type annotations to 23 modules covering:
- Metrics classes (ConsumerMetrics, ProducerMetrics, etc.)
- Spec classes (ConsumerSpec, ProducerSpec, SubscriberSpec, etc.)
- Service classes with add_args() and run() methods
- Utility functions (logging, pubsub, clients)
- AsyncProcessor methods

All 93 public functions now fully typed.

Refs #785
2026-04-13 18:26:53 -03:00

59 lines
1.3 KiB
Python

from __future__ import annotations
from argparse import ArgumentParser
"""
Document embeddings store base class
"""
import logging
from argparse import ArgumentParser
from .. schema import DocumentEmbeddings
from .. base import FlowProcessor, ConsumerSpec
from .. exceptions import TooManyRequests
from argparse import ArgumentParser
# Module logger
logger = logging.getLogger(__name__)
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:
logger.error(f"Exception in document embeddings store service: {e}", exc_info=True)
raise e
@staticmethod
def add_args(parser: ArgumentParser) -> None:
FlowProcessor.add_args(parser)