Pass 3 of 3 · Deep dive of PHAROSPass 1 · OverviewPass 2 · How it works
Code Observatory / class
EdgeFirstEmbedder
codeintel.embeddings.EdgeFirstEmbedder
PINNED SOURCE Source and edges from the index at this commit. An execution appears only where one was recorded.
PHAROS at 975a38dMIT license
Around this symbol
Search all symbolsLoading
| Symbol | File | Resolved by |
|---|---|---|
| get_embedder | embeddings.py | same file |
| Symbol | File | Resolved by |
|---|---|---|
| __init__ | embeddings.py | same file |
| _edge | embeddings.py | same file |
| _http | embeddings.py | same file |
| _reset_http | embeddings.py | same file |
| describe | embeddings.py | same file |
| embed_documents | embeddings.py | same file |
| embed_query | embeddings.py | same file |
| encode_raw | embeddings.py | same file |
| Symbol | File | Resolved by |
|---|---|---|
| embeddings | embeddings.py | same file |
codeintel.embeddings.EdgeFirstEmbedderbackend/app/codeintel/embeddings.py, lines 367–426Open source
class EdgeFirstEmbedder(Embedder): """The edge's embed server first, the local ONNX model as the fallback. Both run the same model, so their vectors are interchangeable; the edge's ``model_id`` is checked on every answer and a different model is never used. The local model is loaded only when the edge fails (timeout, error, wrong model), and after a failure the edge is skipped for ``retry_after`` seconds so a sleeping edge does not add its timeout to every query. """ def __init__(self, base_url: str, token: str, local: OnnxEmbedder, *, timeout: float = 2.5, retry_after: float = 60.0): self.base_url = base_url.rstrip("/") self.local = local self.model_id = local.model_id self.timeout = timeout self.retry_after = retry_after self._headers = {"Authorization": f"Bearer {token}"} self._client = None # one keep-alive connection: a TLS handshake per query cost ~0.5 s through Funnel self._client_lock = threading.Lock() self._skip_until = 0.0 self.edge_calls = self.local_calls = 0 def _http(self): import httpx with self._client_lock: if self._client is None: self._client = httpx.Client(base_url=self.base_url, headers=self._headers, timeout=self.timeout, limits=httpx.Limits(max_keepalive_connections=2, keepalive_expiry=300)) return self._client def _reset_http(self) -> None: with self._client_lock: client, self._client = self._client, None if client is not None: client.close() def _edge(self, texts: list[str]) -> list[list[float]]: import httpx try: resp = self._http().post("/embed/batch", json={"texts": texts}) except httpx.TransportError: # An idle connection the edge or the proxy closed: retry once on a # fresh one before falling back (the fallback loads the local model). self._reset_http() try: resp = self._http().post("/embed/batch", json={"texts": texts}) except Exception: self._reset_http() raise if resp.status_code != 200: raise EmbeddingUnavailable(f"edge returned HTTP {resp.status_code}") data = resp.json() if data.get("model_id") != self.model_id: raise EmbeddingUnavailable(f"edge runs {data.get('model_id')!r}, not {self.model_id!r}") vectors = data["embeddings"] if len(vectors) != len(texts): raise EmbeddingUnavailable("edge returned the wrong number of vectors")Shows the first 60 of 84 lines. The rest is on GitHub at this commit.
What the index recorded
- Signature
class EdgeFirstEmbedder(Embedder):- File
backend/app/codeintel/embeddings.py- Lines
- 367–450
- Parser
- python-ast
- Git blob
df7f8202f23ca6ad2c57aca5f09b435eb6486d79- Outside this subset
- 6 more edges reach code outside the graph shown here
