@@ -3170,22 +3170,6 @@ static bool run_semantic_query_core(const char *args, cbm_store_t *store, const
31703170 return type_error ;
31713171}
31723172
3173- /* Append the semantic_query vector-search results onto the doc. Returns
3174- * true if semantic_query was provided as a non-array (type error — caller
3175- * should surface to the user). */
3176- static bool run_semantic_query (yyjson_mut_doc * doc , yyjson_mut_val * root , const char * args ,
3177- cbm_store_t * store , const char * project , int limit ) {
3178- cbm_vector_result_t * vresults = NULL ;
3179- int vcount = 0 ;
3180- bool type_error =
3181- run_semantic_query_core (args , store , project , limit , & vresults , & vcount , NULL );
3182- if (vcount > 0 ) {
3183- emit_semantic_results (doc , root , vresults , vcount );
3184- cbm_store_free_vector_results (vresults , vcount );
3185- }
3186- return type_error ;
3187- }
3188-
31893173/* ── Tree output for search_graph ───────────────────────────────────
31903174 * Default response encoding: grouped tree rows (compact_out.h). The same
31913175 * model is available as structured JSON via format:"json"; include_connected
@@ -3620,6 +3604,9 @@ static char *handle_search_graph(cbm_mcp_server_t *srv, const char *args) {
36203604 .min_degree = min_degree ,
36213605 .max_degree = max_degree ,
36223606 };
3607+ bool has_structural_filters = label || name_pattern || qn_pattern || file_pattern ||
3608+ relationship || exclude_entry_points ||
3609+ min_degree != CBM_NOT_FOUND || max_degree != CBM_NOT_FOUND ;
36233610
36243611 if (!legacy_json ) {
36253612 const char * fields [SG_MAX_EXTRA_FIELDS ];
@@ -3640,10 +3627,7 @@ static char *handle_search_graph(cbm_mcp_server_t *srv, const char *args) {
36403627 /* Semantic-only calls get semantic results only: the legacy
36413628 * behavior also ran the UNFILTERED regex search and prepended
36423629 * up to `limit` unrelated enriched nodes to the response. */
3643- bool has_filters = label || name_pattern || qn_pattern || file_pattern ||
3644- relationship || exclude_entry_points ||
3645- min_degree != CBM_NOT_FOUND || max_degree != CBM_NOT_FOUND ;
3646- bool semantic_only = sq_present && !has_filters ;
3630+ bool semantic_only = sq_present && !has_structural_filters ;
36473631
36483632 cbm_sb_t sb ;
36493633 cbm_sb_init (& sb );
@@ -3727,8 +3711,31 @@ static char *handle_search_graph(cbm_mcp_server_t *srv, const char *args) {
37273711 true);
37283712 }
37293713
3714+ cbm_vector_result_t * vresults = NULL ;
3715+ int vcount = 0 ;
3716+ bool sq_present = false;
3717+ bool sq_type_error =
3718+ run_semantic_query_core (args , store , project , limit , & vresults , & vcount , & sq_present );
3719+ if (sq_type_error ) {
3720+ free (project );
3721+ free (label );
3722+ free (name_pattern );
3723+ free (qn_pattern );
3724+ free (file_pattern );
3725+ free (relationship );
3726+ return cbm_mcp_text_result (
3727+ "semantic_query must be an array of keyword strings, e.g. "
3728+ "[\"send\",\"pubsub\",\"publish\"] — not a single string. Split your query "
3729+ "into individual keywords; each is scored independently via per-keyword "
3730+ "min-cosine." ,
3731+ true);
3732+ }
3733+
3734+ bool semantic_only = sq_present && !has_structural_filters ;
37303735 cbm_search_output_t out = {0 };
3731- cbm_store_search (store , & params , & out );
3736+ if (!semantic_only ) {
3737+ cbm_store_search (store , & params , & out );
3738+ }
37323739
37333740 yyjson_mut_doc * doc = yyjson_mut_doc_new (NULL );
37343741 yyjson_mut_val * root = yyjson_mut_obj (doc );
@@ -3767,23 +3774,9 @@ static char *handle_search_graph(cbm_mcp_server_t *srv, const char *args) {
37673774 }
37683775 }
37693776
3770- bool sq_type_error = run_semantic_query (doc , root , args , store , project , limit );
3771-
3772- if (sq_type_error ) {
3773- yyjson_mut_doc_free (doc );
3774- cbm_store_search_free (& out );
3775- free (project );
3776- free (label );
3777- free (name_pattern );
3778- free (qn_pattern );
3779- free (file_pattern );
3780- free (relationship );
3781- return cbm_mcp_text_result (
3782- "semantic_query must be an array of keyword strings, e.g. "
3783- "[\"send\",\"pubsub\",\"publish\"] — not a single string. Split your query "
3784- "into individual keywords; each is scored independently via per-keyword "
3785- "min-cosine." ,
3786- true);
3777+ if (vcount > 0 ) {
3778+ emit_semantic_results (doc , root , vresults , vcount );
3779+ cbm_store_free_vector_results (vresults , vcount );
37873780 }
37883781
37893782 char * json = yy_doc_to_str (doc );
0 commit comments