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 symbolsLoading
| Symbol | File | Resolved by |
|---|---|---|
| _cosine | retrieval.py | same file |
| _supports_iterative_scan | retrieval.py | same file |
| _filter_clauses | retrieval.py | same file |
| Symbol | File | Resolved by |
|---|---|---|
| search | retrieval.py | same file |
| Symbol | File | Resolved by |
|---|---|---|
| Retriever | retrieval.py | same 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 rowsWhat 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
