MCPcopy Create free account
hub / github.com/Graphify-Labs/graphify / _render_query

Function _render_query

graphify/serve.py:2101–2147  ·  view source on GitHub ↗
(
    G: nx.Graph,
    question: str,
    start_nodes: list[str],
    *,
    mode: str,
    depth: int,
    token_budget: int,
    context_filters: list[str] | None,
    graph_path: str | None,
    given: bool = False,
    unresolved: list[str] | None = None,
    scores: dict[str, float] | None = None,
)

Source from the content-addressed store, hash-verified

2099
2100
2101def _render_query(
2102 G: nx.Graph,
2103 question: str,
2104 start_nodes: list[str],
2105 *,
2106 mode: str,
2107 depth: int,
2108 token_budget: int,
2109 context_filters: list[str] | None,
2110 graph_path: str | None,
2111 given: bool = False,
2112 unresolved: list[str] | None = None,
2113 scores: dict[str, float] | None = None,
2114) -> str:
2115 resolved_filters, filter_source = _resolve_context_filters(question, context_filters)
2116 traversal_graph = _filter_graph_by_context(_traversal_view(G), resolved_filters)
2117 nodes, edges = _dfs(traversal_graph, start_nodes, depth) if mode == "dfs" else _bfs(traversal_graph, start_nodes, depth)
2118 header_parts = [
2119 f"Traversal: {mode.upper()} depth={depth}",
2120 f"Start{' (given)' if given else ''}: {[G.nodes[n].get('label', n) for n in start_nodes]}",
2121 ]
2122 if unresolved:
2123 header_parts.append(f"Unresolved seeds (skipped): {unresolved}")
2124 # Name the graph this answer came from. `graphify-out/` resolves against the
2125 # CWD, so running a query from a parent project while thinking about a
2126 # vendored subproject silently answers from the wrong corpus — the output is
2127 # well-formed and confidently wrong, and nothing in it said which graph was
2128 # opened (#2789). Shown relative when the graph is under the CWD (the normal
2129 # case, and short), absolute when it is not — which is exactly the case worth
2130 # noticing. The node count travels with it because "355 nodes" vs "3178
2131 # nodes" is often the first thing that looks wrong.
2132 if graph_path:
2133 header_parts.insert(0, f"Graph: {_display_graph_path(graph_path)} "
2134 f"({G.number_of_nodes()} nodes)")
2135 if resolved_filters:
2136 # A filter that selects nothing used to answer with the seed alone and
2137 # no hint, which reads as "these symbols are unrelated" (#5178).
2138 label = f"Context: {', '.join(resolved_filters)} ({filter_source}"
2139 if not traversal_graph.number_of_edges():
2140 label += ", matched 0 edges"
2141 header_parts.append(label + ")")
2142 header_parts.append(f"{len(nodes)} nodes found")
2143 header = " | ".join(header_parts) + "\n\n"
2144 # Pass the seeds so the queried symbol renders first and survives truncation
2145 # (#BUG2): a branch merge had silently dropped this argument, leaving the
2146 # seed-first ordering as dead code.
2147 return header + _subgraph_to_text(traversal_graph, nodes, edges, token_budget, seeds=start_nodes, scores=scores)
2148
2149
2150def _resolve_path_scoped_symbol(G: nx.Graph, path_part: str, symbol_part: str) -> list[str]:

Callers 1

_query_graph_textFunction · 0.85

Calls 10

_resolve_context_filtersFunction · 0.85
_filter_graph_by_contextFunction · 0.85
_traversal_viewFunction · 0.85
_dfsFunction · 0.85
_bfsFunction · 0.85
_display_graph_pathFunction · 0.85
_subgraph_to_textFunction · 0.85
insertMethod · 0.80
getMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected