Back to the room

Pass 3 of 3 · Deep dive of PHAROSPass 1 · OverviewPass 2 · How it works

Code Observatory / class

Retriever

codeintel.retrieval.Retriever

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 symbols

Loading

Called by (3)
SymbolFileResolved by
assemble_contextcontext.pythrough an import
search_coderouter.pythrough an import
build_mcp_servernative_server.pythrough an import
Contains (13)
SymbolFileResolved by
__init__retrieval.pysame file
_denseretrieval.pysame file
_dense_unavailable_reasonretrieval.pysame file
_expand_graphretrieval.pysame file
_filter_clausesretrieval.pysame file
_finalizeretrieval.pysame file
_fuseretrieval.pysame file
_hydrateretrieval.pysame file
_keywordretrieval.pysame file
_keyword_pythonretrieval.pysame file
_symbol_boostretrieval.pysame file
neighborsretrieval.pysame file
searchretrieval.pysame file
Inside (1)
SymbolFileResolved by
retrievalretrieval.pysame file
codeintel.retrieval.Retrieverbackend/app/codeintel/retrieval.py, lines 196–255Open source
class Retriever:    def __init__(self, db: Session, embedder: Embedder | None) -> None:        self.db = db        self.embedder = embedder        self.is_pg = db.get_bind().dialect.name == "postgresql"    # ── public ─────────────────────────────────────────────────────────    def search(self, query: str, *, mode: str = "auto", k: int = 10,               filters: Filters | None = None, hints: list[str] | None = None) -> SearchOutcome:        """``hints``: identifiers or keywords the caller guesses (an agent's        ``parse_url``, ``redirect``). They feed keyword retrieval and the exact        name boost; the question alone is embedded. With hints, ``auto`` is hybrid."""        if mode not in MODES:            raise ValueError(f"mode must be one of {MODES}")        filters = filters or Filters()        warnings: list[str] = []        timings: dict[str, float] = {}        candidates: dict[str, int] = {}        hints = [h.strip() for h in (hints or []) if h and h.strip()][:20]        terms = list(dict.fromkeys(query_terms(query) + query_terms(" ".join(hints))))        named = " ".join([query, *hints])        effective = mode        dense_reason = self._dense_unavailable_reason(filters)        if mode == "auto":            if dense_reason is None:                effective = "hybrid" if hints else "dense"            else:                effective = "keyword"                warnings.append(f"dense retrieval unavailable ({dense_reason}); used keyword retrieval only")        elif mode in ("dense", "hybrid", "graph") and dense_reason is not None:            raise ModeUnavailable(mode, dense_reason)        keyword: list[tuple[str, float]] = []        dense: list[tuple[str, float]] = []        if effective in ("keyword", "hybrid", "graph"):            t = time.perf_counter()            keyword = self._keyword(terms, filters, CANDIDATES if effective != "keyword" else max(k * 3, CANDIDATES))            timings["keyword"] = (time.perf_counter() - t) * 1000            candidates["keyword"] = len(keyword)            if not terms:                warnings.append("query has no searchable terms for keyword retrieval")        if effective in ("dense", "hybrid", "graph"):            t = time.perf_counter()            try:                qvec = self.embedder.embed_query(query)  # type: ignore[union-attr]            except EmbeddingUnavailable as exc:                if mode == "auto":                    warnings.append(f"query embedding failed ({exc}); used keyword retrieval only")                    effective = "keyword"                    qvec = None                else:                    raise ModeUnavailable(mode, str(exc)) from exc            timings["embed_query"] = (time.perf_counter() - t) * 1000            if qvec is not None:                t = time.perf_counter()                dense = self._dense(qvec, filters, CANDIDATES)                timings["dense"] = (time.perf_counter() - t) * 1000                candidates["dense"] = len(dense)

Shows the first 60 of 395 lines. The rest is on GitHub at this commit.

What the index recorded

Signature
class Retriever:
File
backend/app/codeintel/retrieval.py
Lines
196–590
Parser
python-ast
Git blob
884729a39ae0b3d340ad83f75946677dcddf3791
Outside this subset
16 more edges reach code outside the graph shown here

Read it on GitHub at this commit