Back to the room

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

Code Observatory / method

_dense

codeintel.retrieval.Retriever._dense

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

Calls (3)
SymbolFileResolved by
_cosineretrieval.pysame file
_supports_iterative_scanretrieval.pysame file
_filter_clausesretrieval.pysame file
Called by (1)
SymbolFileResolved by
searchretrieval.pysame file
Inside (1)
SymbolFileResolved by
Retrieverretrieval.pysame file
codeintel.retrieval.Retriever._densebackend/app/codeintel/retrieval.py, lines 370–405Open source
    def _dense(self, qvec: list[float], filters: Filters, limit: int) -> list[tuple[str, float]]:        assert self.embedder is not None        model = self.embedder.model_id        if not self.is_pg:            rows = self.db.execute(                select(DocumentChunk.id, DocumentChunk.embedding).where(                    DocumentChunk.embedding_model == model, *self._filter_clauses(filters)                )            ).all()            scored = [(str(cid), _cosine(qvec, emb)) for cid, emb in rows if emb]            scored.sort(key=lambda x: (-x[1], x[0]))            return scored[:limit]        # Higher ef_search keeps recall up when filters discard candidates        # after the HNSW scan (pgvector post-filters). pgvector >= 0.8 can        # also keep scanning until enough rows pass the filter, which matters        # once one database holds many repositories; results are re-sorted        # below because the relaxed order is only approximately sorted.        self.db.execute(text("SELECT set_config('hnsw.ef_search', :ef, true)"), {"ef": str(max(100, limit * 4))})        if _supports_iterative_scan(self.db):            self.db.execute(text("SELECT set_config('hnsw.iterative_scan', 'relaxed_order', true)"))        distance = DocumentChunk.embedding.op("<=>", return_type=Float)(            bindparam("qvec", qvec, type_=EmbeddingVector())        )        stmt = (            select(DocumentChunk.id, distance.label("distance"))            .where(                DocumentChunk.embedding.isnot(None),                DocumentChunk.embedding_model == model,                *self._filter_clauses(filters),            )            .order_by(distance)            .limit(limit)        )        rows = sorted(((str(cid), 1.0 - float(dist)) for cid, dist in self.db.execute(stmt)),                      key=lambda x: (-x[1], x[0]))        return rows

What the index recorded

Signature
def _dense(self, qvec: list[float], filters: Filters, limit: int) -> list[tuple[str, float]]:
File
backend/app/codeintel/retrieval.py
Lines
370–405
Parser
python-ast
Git blob
884729a39ae0b3d340ad83f75946677dcddf3791
Call sites
20 named, 6 resolved, 14 left unlinked
Outside this subset
3 more edges reach code outside the graph shown here

Read it on GitHub at this commit