"""EmbeddingProvider port — 文本向量化能力契约。""" from typing import Protocol, runtime_checkable @runtime_checkable class EmbeddingProvider(Protocol): def is_available(self) -> bool: """进程内 embedding 已配置且可发起调用(无 key / 未初始化 client 时为 False)。""" ... async def embed_text(self, text: str) -> list[float]: """Embed a single text into a vector.""" ... async def embed_texts(self, texts: list[str]) -> list[list[float]]: """Embed multiple texts into vectors.""" ... def embed_text_sync(self, text: str) -> list[float]: """同步嵌入单条文本(Celery / sync DB 会话)。""" ... def embed_texts_sync(self, texts: list[str]) -> list[list[float]]: """同步嵌入多条文本(Celery / sync DB 会话)。""" ...