|
34 | 34 | # Environment |
35 | 35 | QDRANT_URL = os.environ.get("QDRANT_URL", "http://qdrant:6333") |
36 | 36 |
|
| 37 | +# Remote embedding support |
| 38 | +try: |
| 39 | + from scripts.embedder import RemoteEmbeddingStub |
| 40 | + from scripts.ingest.qdrant import embed_batch as _embed_batch_remote |
| 41 | + _REMOTE_EMBED_AVAILABLE = True |
| 42 | +except ImportError: |
| 43 | + RemoteEmbeddingStub = None # type: ignore |
| 44 | + _embed_batch_remote = None # type: ignore |
| 45 | + _REMOTE_EMBED_AVAILABLE = False |
| 46 | + |
| 47 | + |
| 48 | +def _embed_text(model, text: str, model_name: str) -> list: |
| 49 | + """Embed text using either local model or remote service. |
| 50 | + |
| 51 | + Detects RemoteEmbeddingStub and routes to embed_batch() accordingly. |
| 52 | + """ |
| 53 | + is_remote_stub = ( |
| 54 | + RemoteEmbeddingStub is not None |
| 55 | + and isinstance(model, RemoteEmbeddingStub) |
| 56 | + ) |
| 57 | + |
| 58 | + if is_remote_stub and _REMOTE_EMBED_AVAILABLE and _embed_batch_remote is not None: |
| 59 | + # Use remote embedding service |
| 60 | + vecs = _embed_batch_remote(model, [text]) |
| 61 | + return vecs[0] if isinstance(vecs[0], list) else vecs[0].tolist() |
| 62 | + else: |
| 63 | + # Local embedding |
| 64 | + return next(model.embed([text])).tolist() |
| 65 | + |
37 | 66 |
|
38 | 67 | async def _memory_store_impl( |
39 | 68 | information: str, |
@@ -116,7 +145,8 @@ def _lex_hash_vector(text: str, dim: int = LEX_VECTOR_DIM) -> list[float]: |
116 | 145 | from scripts.mcp_impl.admin_tools import _get_embedding_model |
117 | 146 | model = _get_embedding_model(model_name) |
118 | 147 |
|
119 | | - dense = next(model.embed([str(information)])).tolist() |
| 148 | + # Use helper that handles remote vs local embedding |
| 149 | + dense = _embed_text(model, str(information), model_name) |
120 | 150 |
|
121 | 151 | lex = _lex_hash_vector(str(information)) |
122 | 152 |
|
@@ -254,7 +284,8 @@ def _lex_hash_vector(text: str, dim: int = LEX_VECTOR_DIM) -> list[float]: |
254 | 284 | from scripts.mcp_impl.admin_tools import _get_embedding_model |
255 | 285 | model = _get_embedding_model(model_name) |
256 | 286 |
|
257 | | - dense_query = next(model.embed([str(query)])).tolist() |
| 287 | + # Use helper that handles remote vs local embedding |
| 288 | + dense_query = _embed_text(model, str(query), model_name) |
258 | 289 | lex_query = _lex_hash_vector(str(query)) |
259 | 290 |
|
260 | 291 | client = QdrantClient( |
|
0 commit comments