2026-03-18 17:18:23 +08:00
|
|
|
|
"""EmbeddingProvider port — 文本向量化能力契约。"""
|
|
|
|
|
|
|
|
|
|
|
|
from typing import Protocol, runtime_checkable
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@runtime_checkable
|
|
|
|
|
|
class EmbeddingProvider(Protocol):
|
2026-04-03 11:43:16 +08:00
|
|
|
|
def is_available(self) -> bool:
|
|
|
|
|
|
"""进程内 embedding 已配置且可发起调用(无 key / 未初始化 client 时为 False)。"""
|
|
|
|
|
|
...
|
|
|
|
|
|
|
2026-03-18 17:18:23 +08:00
|
|
|
|
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."""
|
|
|
|
|
|
...
|
2026-04-03 11:43:16 +08:00
|
|
|
|
|
|
|
|
|
|
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 会话)。"""
|
|
|
|
|
|
...
|