@@ -2995,22 +2995,6 @@ static bool run_semantic_query_core(const char *args, cbm_store_t *store, const
29952995 return type_error ;
29962996}
29972997
2998- /* Append the semantic_query vector-search results onto the doc. Returns
2999- * true if semantic_query was provided as a non-array (type error — caller
3000- * should surface to the user). */
3001- static bool run_semantic_query (yyjson_mut_doc * doc , yyjson_mut_val * root , const char * args ,
3002- cbm_store_t * store , const char * project , int limit ) {
3003- cbm_vector_result_t * vresults = NULL ;
3004- int vcount = 0 ;
3005- bool type_error =
3006- run_semantic_query_core (args , store , project , limit , & vresults , & vcount , NULL );
3007- if (vcount > 0 ) {
3008- emit_semantic_results (doc , root , vresults , vcount );
3009- cbm_store_free_vector_results (vresults , vcount );
3010- }
3011- return type_error ;
3012- }
3013-
30142998/* ── Tree output for search_graph ───────────────────────────────────
30152999 * Default response encoding: grouped tree rows (compact_out.h). The same
30163000 * model is available as structured JSON via format:"json"; include_connected
@@ -3445,6 +3429,9 @@ static char *handle_search_graph(cbm_mcp_server_t *srv, const char *args) {
34453429 .min_degree = min_degree ,
34463430 .max_degree = max_degree ,
34473431 };
3432+ bool has_structural_filters = label || name_pattern || qn_pattern || file_pattern ||
3433+ relationship || exclude_entry_points ||
3434+ min_degree != CBM_NOT_FOUND || max_degree != CBM_NOT_FOUND ;
34483435
34493436 if (!legacy_json ) {
34503437 const char * fields [SG_MAX_EXTRA_FIELDS ];
@@ -3465,10 +3452,7 @@ static char *handle_search_graph(cbm_mcp_server_t *srv, const char *args) {
34653452 /* Semantic-only calls get semantic results only: the legacy
34663453 * behavior also ran the UNFILTERED regex search and prepended
34673454 * up to `limit` unrelated enriched nodes to the response. */
3468- bool has_filters = label || name_pattern || qn_pattern || file_pattern ||
3469- relationship || exclude_entry_points ||
3470- min_degree != CBM_NOT_FOUND || max_degree != CBM_NOT_FOUND ;
3471- bool semantic_only = sq_present && !has_filters ;
3455+ bool semantic_only = sq_present && !has_structural_filters ;
34723456
34733457 cbm_sb_t sb ;
34743458 cbm_sb_init (& sb );
@@ -3552,8 +3536,31 @@ static char *handle_search_graph(cbm_mcp_server_t *srv, const char *args) {
35523536 true);
35533537 }
35543538
3539+ cbm_vector_result_t * vresults = NULL ;
3540+ int vcount = 0 ;
3541+ bool sq_present = false;
3542+ bool sq_type_error =
3543+ run_semantic_query_core (args , store , project , limit , & vresults , & vcount , & sq_present );
3544+ if (sq_type_error ) {
3545+ free (project );
3546+ free (label );
3547+ free (name_pattern );
3548+ free (qn_pattern );
3549+ free (file_pattern );
3550+ free (relationship );
3551+ return cbm_mcp_text_result (
3552+ "semantic_query must be an array of keyword strings, e.g. "
3553+ "[\"send\",\"pubsub\",\"publish\"] — not a single string. Split your query "
3554+ "into individual keywords; each is scored independently via per-keyword "
3555+ "min-cosine." ,
3556+ true);
3557+ }
3558+
3559+ bool semantic_only = sq_present && !has_structural_filters ;
35553560 cbm_search_output_t out = {0 };
3556- cbm_store_search (store , & params , & out );
3561+ if (!semantic_only ) {
3562+ cbm_store_search (store , & params , & out );
3563+ }
35573564
35583565 yyjson_mut_doc * doc = yyjson_mut_doc_new (NULL );
35593566 yyjson_mut_val * root = yyjson_mut_obj (doc );
@@ -3592,23 +3599,9 @@ static char *handle_search_graph(cbm_mcp_server_t *srv, const char *args) {
35923599 }
35933600 }
35943601
3595- bool sq_type_error = run_semantic_query (doc , root , args , store , project , limit );
3596-
3597- if (sq_type_error ) {
3598- yyjson_mut_doc_free (doc );
3599- cbm_store_search_free (& out );
3600- free (project );
3601- free (label );
3602- free (name_pattern );
3603- free (qn_pattern );
3604- free (file_pattern );
3605- free (relationship );
3606- return cbm_mcp_text_result (
3607- "semantic_query must be an array of keyword strings, e.g. "
3608- "[\"send\",\"pubsub\",\"publish\"] — not a single string. Split your query "
3609- "into individual keywords; each is scored independently via per-keyword "
3610- "min-cosine." ,
3611- true);
3602+ if (vcount > 0 ) {
3603+ emit_semantic_results (doc , root , vresults , vcount );
3604+ cbm_store_free_vector_results (vresults , vcount );
36123605 }
36133606
36143607 char * json = yy_doc_to_str (doc );
0 commit comments