@rigstate/mcp 0.5.1 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +25 -11
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
- package/src/tools/query-brain.ts +30 -12
package/dist/index.js
CHANGED
|
@@ -974,19 +974,30 @@ architecture rules, decisions, and constraints.`,
|
|
|
974
974
|
}
|
|
975
975
|
});
|
|
976
976
|
async function generateQueryEmbedding(query) {
|
|
977
|
-
const
|
|
978
|
-
|
|
979
|
-
|
|
977
|
+
const openRouterKey = process.env.OPENROUTER_API_KEY;
|
|
978
|
+
const googleKey = process.env.GOOGLE_GENERATIVE_AI_API_KEY;
|
|
979
|
+
if (!openRouterKey && !googleKey) {
|
|
980
|
+
console.warn("Neither OPENROUTER_API_KEY nor GOOGLE_GENERATIVE_AI_API_KEY found, skipping vector search.");
|
|
980
981
|
return null;
|
|
981
982
|
}
|
|
982
983
|
try {
|
|
983
|
-
const { google } = await import("@ai-sdk/google");
|
|
984
984
|
const { embed } = await import("ai");
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
985
|
+
if (openRouterKey) {
|
|
986
|
+
const { createOpenRouter } = await import("@openrouter/ai-sdk-provider");
|
|
987
|
+
const openrouter = createOpenRouter({ apiKey: openRouterKey });
|
|
988
|
+
const { embedding } = await embed({
|
|
989
|
+
model: openrouter.embedding("google/text-embedding-004"),
|
|
990
|
+
value: query.replace(/\n/g, " ")
|
|
991
|
+
});
|
|
992
|
+
return embedding;
|
|
993
|
+
} else {
|
|
994
|
+
const { google } = await import("@ai-sdk/google");
|
|
995
|
+
const { embedding } = await embed({
|
|
996
|
+
model: google.embedding("text-embedding-004"),
|
|
997
|
+
value: query.replace(/\n/g, " ")
|
|
998
|
+
});
|
|
999
|
+
return embedding;
|
|
1000
|
+
}
|
|
990
1001
|
} catch (error) {
|
|
991
1002
|
console.error("Failed to generate embedding for search:", error);
|
|
992
1003
|
return null;
|
|
@@ -999,12 +1010,14 @@ async function queryBrain(supabase, userId, projectId, query, limit = 8, thresho
|
|
|
999
1010
|
}
|
|
1000
1011
|
const embedding = await generateQueryEmbedding(query);
|
|
1001
1012
|
let memories = [];
|
|
1013
|
+
console.log(`Searching brain for "${query}" (limit: ${limit}, threshold: ${threshold})`);
|
|
1014
|
+
console.log(`Embedding present: ${!!embedding}`);
|
|
1002
1015
|
const { data: searchResults, error: searchError } = await supabase.rpc("hybrid_search_memories", {
|
|
1003
1016
|
p_project_id: projectId,
|
|
1004
1017
|
p_query: query,
|
|
1005
|
-
p_embedding: embedding,
|
|
1018
|
+
p_embedding: embedding || null,
|
|
1006
1019
|
p_limit: limit,
|
|
1007
|
-
p_similarity_threshold: threshold || 0.
|
|
1020
|
+
p_similarity_threshold: threshold || 0.1
|
|
1008
1021
|
});
|
|
1009
1022
|
if (searchError) {
|
|
1010
1023
|
console.error("Hybrid search error:", searchError);
|
|
@@ -1020,6 +1033,7 @@ async function queryBrain(supabase, userId, projectId, query, limit = 8, thresho
|
|
|
1020
1033
|
}));
|
|
1021
1034
|
}
|
|
1022
1035
|
} else if (searchResults) {
|
|
1036
|
+
console.log(`Found ${searchResults.length} results from RPC`);
|
|
1023
1037
|
memories = searchResults.map((m) => ({
|
|
1024
1038
|
id: m.id,
|
|
1025
1039
|
content: m.content,
|