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

Function indexDiffEntry

scripts/sparc2/src/vector/vectorStore.ts:151–197  ·  view source on GitHub ↗
(entry: DiffEntry)

Source from the content-addressed store, hash-verified

149 * @param entry Diff entry to index
150 */
151export async function indexDiffEntry(entry: DiffEntry): Promise<void> {
152 try {
153 // If OpenAI client is not available, use mock implementation
154 if (!openai) {
155 console.debug("Vector store: Indexing diff entry (mock)", entry.id, entry.file);
156 return;
157 }
158
159 // Ensure vector store is initialized
160 const storeId = await initializeVectorStore();
161
162 // Create a text file with the diff entry
163 const content = `Diff Entry (${entry.id})
164File: ${entry.file}
165Diff:
166${entry.diff}
167Metadata: ${JSON.stringify(entry.metadata || {}, null, 2)}`;
168
169 const file = new File(
170 [content],
171 `diff-${entry.id}.txt`,
172 { type: "text/plain" },
173 );
174
175 // Upload the file to OpenAI
176 const uploadedFile = await openai.files.create({
177 file,
178 purpose: "assistants",
179 });
180
181 // Add the file to the vector store
182 await openai.vectorStores.files.create(storeId, {
183 file_id: uploadedFile.id,
184 });
185
186 console.debug("Diff entry indexed in vector database", {
187 id: entry.id,
188 file: entry.file,
189 diffPreview: entry.diff.substring(0, 50) + (entry.diff.length > 50 ? "..." : ""),
190 });
191 } catch (error: unknown) {
192 console.debug("Failed to index diff entry in vector database, using mock", {
193 error: String(error),
194 });
195 console.debug("Vector store: Indexing diff entry (mock)", entry.id, entry.file);
196 }
197}
198
199/**
200 * Search for diff entries similar to the query

Callers 2

analyzeAndDiffMethod · 0.90

Calls 1

initializeVectorStoreFunction · 0.70

Tested by

no test coverage detected