Skip to content

Commit 0d705c9

Browse files
clydinalan-agius4
authored andcommitted
refactor(@angular/cli): implement weighted search for MCP examples
This commit improves the relevance of the `find_examples` MCP server tool by implementing weighted search ranking. The FTS5 query now uses the `bm25()` ranking function to assign a higher weight to matches found in more important fields. Specifically, matches in the `title`, `summary`, and `keywords` are now weighted more heavily than matches in the main content. This results in more accurate and intuitive search results, as examples where the query terms are central to the topic are ranked higher.
1 parent d014630 commit 0d705c9

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

packages/angular/cli/src/commands/mcp/tools/examples.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,12 @@ async function createFindExampleHandler({ exampleDatabasePath }: McpToolContext)
158158
if (whereClauses.length > 0) {
159159
sql += ` WHERE ${whereClauses.join(' AND ')}`;
160160
}
161-
sql += ' ORDER BY rank;';
161+
162+
// Order the results by relevance using the BM25 algorithm.
163+
// The weights assigned to each column boost the ranking of documents where the
164+
// search term appears in a more important field.
165+
// Column order: title, summary, keywords, required_packages, related_concepts, related_tools, content
166+
sql += ' ORDER BY bm25(examples_fts, 10.0, 5.0, 5.0, 1.0, 2.0, 1.0, 1.0);';
162167

163168
const queryStatement = db.prepare(sql);
164169

0 commit comments

Comments
 (0)