Back to the room

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

Code Observatory / method

_keyword_python

codeintel.retrieval.Retriever._keyword_python

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 (1)
SymbolFileResolved by
_filter_clausesretrieval.pysame file
Called by (1)
SymbolFileResolved by
_keywordretrieval.pysame file
Inside (1)
SymbolFileResolved by
Retrieverretrieval.pysame file
codeintel.retrieval.Retriever._keyword_pythonbackend/app/codeintel/retrieval.py, lines 341–366Open source
    def _keyword_python(self, terms: list[str], filters: Filters, limit: int) -> list[tuple[str, float]]:        rows = self.db.execute(            select(DocumentChunk.id, DocumentChunk.search_text).where(*self._filter_clauses(filters))        ).all()        docs = [(str(cid), (txt or "").split()) for cid, txt in rows]        if not docs:            return []        n = len(docs)        avgdl = sum(len(d) for _, d in docs) / n or 1.0        df = Counter()        for _, toks in docs:            df.update(set(toks))        scored = []        for cid, toks in docs:            tf = Counter(toks)            s = 0.0            for term in terms:                if term not in tf:                    continue                idf = math.log(1 + (n - df[term] + 0.5) / (df[term] + 0.5))                f = tf[term]                s += idf * f * 2.2 / (f + 1.2 * (0.25 + 0.75 * len(toks) / avgdl))            if s > 0:                scored.append((cid, s))        scored.sort(key=lambda x: (-x[1], x[0]))        return scored[:limit]

What the index recorded

Signature
def _keyword_python(self, terms: list[str], filters: Filters, limit: int) -> list[tuple[str, float]]:
File
backend/app/codeintel/retrieval.py
Lines
341–366
Parser
python-ast
Git blob
884729a39ae0b3d340ad83f75946677dcddf3791
Call sites
15 named, 3 resolved, 12 left unlinked
Outside this subset
2 more edges reach code outside the graph shown here

Read it on GitHub at this commit