Pass 3 of 3 · Deep dive of PHAROSPass 1 · OverviewPass 2 · How it works
Code Observatory / function
assemble_context
codeintel.context.assemble_context
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 |
|---|---|---|
| _Budget | context.py | same file |
| _render | context.py | same file |
| hit_to_dict | context.py | same file |
| resolve_repositories | context.py | same file |
| select_rules | context.py | same file |
| source_requests | context.py | same file |
| Filters | retrieval.py | through an import |
| Retriever | retrieval.py | through an import |
| resolve_sources | source.py | through an import |
| Symbol | File | Resolved by |
|---|---|---|
| retrieve_context | router.py | through an import |
| build_mcp_server | native_server.py | through an import |
| Symbol | File | Resolved by |
|---|---|---|
| context | context.py | same file |
codeintel.context.assemble_contextbackend/app/codeintel/context.py, lines 154–213Open source
def assemble_context(db: Session, embedder: Embedder | None, req: ContextRequest, *, fetch_token: str | None = None) -> dict: t0 = time.perf_counter() timings: dict[str, float] = {} repos = resolve_repositories(db, req.repository) filters = Filters( repository_ids=[r.id for r in repos] or None, languages=req.languages, kinds=req.kinds, path_prefix=req.path_prefix, ) retriever = Retriever(db, embedder) outcome = retriever.search(req.query, mode=req.mode, k=req.max_chunks, filters=filters, hints=req.hints) timings.update({f"retrieval_{k}": v for k, v in outcome.timings_ms.items()}) chunks = [hit_to_dict(h, i) for i, h in enumerate(outcome.hits, start=1)] t = time.perf_counter() if req.include_code and outcome.hits: results = resolve_sources(source_requests(db, outcome.hits), token=fetch_token) for c in chunks: res = results.get(c["chunk_id"]) c["code_status"] = res.status if res else "unavailable:unknown" c["code"] = res.code if res else None c["verified"] = bool(res and res.verified) if c["kind"] == "module" and res and res.code is not None: c["code_truncated_to_lines"] = MODULE_CODE_LINES else: for c in chunks: c["code_status"] = "not_requested" c["code"] = None c["verified"] = False timings["resolve_code"] = (time.perf_counter() - t) * 1000 related: list[dict] = [] if req.include_related and outcome.hits: t = time.perf_counter() hit_ids = {h.chunk_id for h in outcome.hits} edges = retriever.neighbors([h.chunk_id for h in outcome.hits[:3]], limit=12) neighbor_ids = [uuid.UUID(n) for _, n, _ in edges if n not in hit_ids] rows = { str(c.id): c for c in db.execute(select(DocumentChunk).where(DocumentChunk.id.in_(neighbor_ids))).scalars() } if neighbor_ids else {} seen = set() for seed, neighbor, relation in edges: c = rows.get(neighbor) if c is None or neighbor in seen: continue seen.add(neighbor) meta = c.chunk_metadata or {} related.append({ "chunk_id": neighbor, "relation": relation, "via_chunk_id": seed, "path": meta.get("path"), "symbol": c.symbol_name, "kind": c.ast_node_type, "start_line": c.start_line, "end_line": c.end_line,Shows the first 60 of 108 lines. The rest is on GitHub at this commit.
What the index recorded
- Signature
def assemble_context(db: Session, embedder: Embedder | None, req: ContextRequest, *, fetch_token: str | None) -> dict:- File
backend/app/codeintel/context.py- Lines
- 154–261
- Parser
- python-ast
- Git blob
0c4a7dd4639651a5c13142d168630e344439f22a- Call sites
- 31 named, 12 resolved, 19 left unlinked
- Outside this subset
- 18 more edges reach code outside the graph shown here
