MCPcopy Create free account
hub / github.com/agenticsorg/edge-agents / searchDiffEntries

Function searchDiffEntries

scripts/sparc2/src/vector/vectorStore.ts:205–264  ·  view source on GitHub ↗
(
  query: string,
  maxResults: number = 5,
)

Source from the content-addressed store, hash-verified

203 * @returns Array of matching diff entries with similarity scores
204 */
205export async function searchDiffEntries(
206 query: string,
207 maxResults: number = 5,
208): Promise<VectorSearchResult[]> {
209 try {
210 // If OpenAI client is not available, use mock implementation
211 if (!openai) {
212 console.debug("Vector store: Searching for diff entries (mock)", query);
213 return [];
214 }
215
216 // Ensure vector store is initialized
217 const storeId = await initializeVectorStore();
218
219 // Search the vector store
220 const searchResponse = await openai.vectorStores.search(storeId, {
221 query,
222 max_num_results: maxResults,
223 });
224
225 // Transform the results into the expected format
226 const results: VectorSearchResult[] = searchResponse.data.map((result: any) => {
227 // Extract diff entry information from the content
228 const content = result.content[0]?.text || "";
229
230 // Parse the content to extract diff entry information
231 const idMatch = content.match(/Diff Entry \((.*?)\)/);
232 const fileMatch = content.match(/File: (.*?)$/m);
233 const diffMatch = content.match(/Diff:\n([\s\S]*?)Metadata:/);
234 const metadataMatch = content.match(/Metadata: ([\s\S]*?)$/);
235
236 const id = idMatch ? idMatch[1] : "";
237 const file = fileMatch ? fileMatch[1] : "";
238 const diff = diffMatch ? diffMatch[1].trim() : "";
239 const metadata = metadataMatch ? JSON.parse(metadataMatch[1]) : {};
240
241 return {
242 entry: {
243 id,
244 file,
245 diff,
246 metadata,
247 } as DiffEntry,
248 score: result.score || 0,
249 };
250 });
251
252 console.debug("Searched for diff entries", {
253 query,
254 maxResults,
255 resultsCount: results.length,
256 });
257
258 return results;
259 } catch (error: unknown) {
260 console.debug("Failed to search diff entries, using mock", { error: String(error) });
261 console.debug("Vector store: Searching for diff entries (mock)", query);
262 return [];

Callers 4

searchCommandFunction · 0.90
tools.tsFile · 0.90
searchVectorStoreFunction · 0.70

Calls 1

initializeVectorStoreFunction · 0.70

Tested by

no test coverage detected