julee.services.knowledge_service ================================ .. py:module:: julee.services.knowledge_service .. autoapi-nested-parse:: Knowledge Service module for julee domain. This module provides the KnowledgeService protocol and factory function for creating configured knowledge service instances. The factory routes to the appropriate implementation based on the service_api configuration. Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/julee/services/knowledge_service/anthropic/index /autoapi/julee/services/knowledge_service/factory/index /autoapi/julee/services/knowledge_service/knowledge_service/index /autoapi/julee/services/knowledge_service/memory/index Classes ------- .. autoapisummary:: julee.services.knowledge_service.FileRegistrationResult julee.services.knowledge_service.KnowledgeService julee.services.knowledge_service.QueryResult Functions --------- .. autoapisummary:: julee.services.knowledge_service.ensure_knowledge_service Package Contents ---------------- .. py:class:: FileRegistrationResult(/, **data) Bases: :py:obj:`pydantic.BaseModel` Result of registering a file with a knowledge service. .. py:attribute:: created_at :type: Optional[datetime.datetime] :value: None .. py:attribute:: document_id :type: str :value: None .. py:attribute:: knowledge_service_file_id :type: str :value: None .. py:attribute:: registration_metadata :type: Dict[str, Any] :value: None .. py:class:: KnowledgeService Bases: :py:obj:`Protocol` Protocol for interacting with external knowledge services. This protocol defines the interface for external operations that were moved out of the repository layer. Implementations handle the specifics of different knowledge service APIs (Anthropic, OpenAI, etc.). .. py:method:: execute_query(config, query_text, service_file_ids = None, query_metadata = None, assistant_prompt = None) :async: Execute a query against the external knowledge service. This method executes a text query against the knowledge service, optionally scoping the query to specific documents that have been previously registered with the service. :param config: KnowledgeServiceConfig for the service to use :param query_text: The query to execute (natural language or structured) :param service_file_ids: Optional list of service file IDs to provide as context for the query. These are the IDs returned by the knowledge service from register_file operations, and are included in the query to give the service access to specific documents. :param query_metadata: Optional service-specific metadata and configuration options such as model selection, temperature, max_tokens, etc. The structure depends on the specific knowledge service being used. :param assistant_prompt: Optional assistant message content to constrain or prime the model's response. This is added as the final assistant message before the model generates its response, allowing control over response format and structure. :returns: QueryResult containing query results and execution metadata .. rubric:: Implementation Notes - Must be idempotent: same query returns consistent results - Service file IDs are provided as context to enhance query responses - Should handle service unavailability gracefully - Query results should be structured as domain objects - Should track execution time and metadata - Must handle various query formats (natural language, structured, etc.) - Should validate that service_file_ids exist in the service before including them in the query context .. rubric:: Workflow Context In Temporal workflows, this method is implemented as an activity to ensure query results are durably stored and can be replayed consistently. .. py:method:: register_file(config, document) :async: Register a document file with the external knowledge service. This method registers a document with the external knowledge service, allowing that service to analyze and index the document content for future queries. :param config: KnowledgeServiceConfig for the service to use :param document: Document domain object to register :returns: FileRegistrationResult containing registration details and the service's internal file identifier .. rubric:: Implementation Notes - Must be idempotent: re-registering same document returns same result - Should handle service unavailability gracefully - Must return the service's internal file ID for future queries - Document content is accessed directly from the Document object - Should handle various document formats and sizes .. rubric:: Workflow Context In Temporal workflows, this method is implemented as an activity to ensure registration results are durably stored and consistent across workflow replays. .. py:class:: QueryResult(/, **data) Bases: :py:obj:`pydantic.BaseModel` Result of a knowledge service query execution. .. py:attribute:: created_at :type: Optional[datetime.datetime] :value: None .. py:attribute:: execution_time_ms :type: Optional[int] :value: None .. py:attribute:: query_id :type: str :value: None .. py:attribute:: query_text :type: str :value: None .. py:attribute:: result_data :type: Dict[str, Any] :value: None .. py:function:: ensure_knowledge_service(service) Ensure an object satisfies the KnowledgeService protocol. :param service: The service implementation to validate :returns: The validated service (type checker knows it satisfies KnowledgeService) :raises TypeError: If the service doesn't satisfy the protocol