@@ -17,10 +17,12 @@ import { generateServerName } from "../../shared/nameUtils.js";
1717export async function fetchDocumentation ( {
1818 repoData,
1919 env,
20+ ctx,
2021 initiatedFromSearch = false ,
2122} : {
2223 repoData : RepoData ;
2324 env : any ;
25+ ctx : any ;
2426 initiatedFromSearch ?: boolean ;
2527} ) : Promise < {
2628 fileUsed : string ;
@@ -247,33 +249,7 @@ export async function fetchDocumentation({
247249
248250 // Store documentation in vector database for later search
249251 if ( content && owner && repo ) {
250- try {
251- // First check if vectors exist in KV cache
252- let vectorsExist = await getIsIndexedFromCache ( owner , repo , env ) ;
253-
254- // Only store vectors if they don't exist yet
255- if ( ! vectorsExist ) {
256- // Pass the Vectorize binding from env
257- await storeDocumentationVectors (
258- owner ,
259- repo ,
260- content ,
261- fileUsed ,
262- env . VECTORIZE ,
263- ) ;
264-
265- // Update the cache to indicate vectors now exist
266- await cacheIsIndexed ( owner , repo , true , env ) ;
267- console . log ( `Stored documentation vectors for ${ owner } /${ repo } ` ) ;
268- } else {
269- console . log (
270- `Documentation vectors already exist for ${ owner } /${ repo } , skipping indexing` ,
271- ) ;
272- }
273- } catch ( error ) {
274- console . error ( `Failed to store documentation vectors: ${ error } ` ) ;
275- // Continue despite vector storage failure
276- }
252+ ctx . waitUntil ( indexDocumentation ( owner , repo , content , fileUsed , env ) ) ;
277253 }
278254 }
279255
@@ -293,6 +269,41 @@ export async function fetchDocumentation({
293269 } ;
294270}
295271
272+ async function indexDocumentation (
273+ owner : string ,
274+ repo : string ,
275+ content : string ,
276+ fileUsed : string ,
277+ env : any ,
278+ ) {
279+ try {
280+ // First check if vectors exist in KV cache
281+ let vectorsExist = await getIsIndexedFromCache ( owner , repo , env ) ;
282+
283+ // Only store vectors if they don't exist yet
284+ if ( ! vectorsExist ) {
285+ // Pass the Vectorize binding from env
286+ await storeDocumentationVectors (
287+ owner ,
288+ repo ,
289+ content ,
290+ fileUsed ,
291+ env . VECTORIZE ,
292+ ) ;
293+
294+ // Update the cache to indicate vectors now exist
295+ await cacheIsIndexed ( owner , repo , true , env ) ;
296+ console . log ( `Stored documentation vectors for ${ owner } /${ repo } ` ) ;
297+ } else {
298+ console . log (
299+ `Documentation vectors already exist for ${ owner } /${ repo } , skipping indexing` ,
300+ ) ;
301+ }
302+ } catch ( error ) {
303+ console . error ( `Failed to store documentation vectors: ${ error } ` ) ;
304+ // Continue despite vector storage failure
305+ }
306+ }
296307/**
297308 * Search documentation using vector search
298309 * Will fetch and index documentation if none exists
@@ -302,11 +313,13 @@ export async function searchRepositoryDocumentation({
302313 query,
303314 forceReindex = false ,
304315 env,
316+ ctx,
305317} : {
306318 repoData : RepoData ;
307319 query : string ;
308320 forceReindex ?: boolean ;
309321 env : any ;
322+ ctx : any ;
310323} ) : Promise < {
311324 searchQuery : string ;
312325 content : { type : "text" ; text : string } [ ] ;
@@ -346,7 +359,7 @@ export async function searchRepositoryDocumentation({
346359 await cacheIsIndexed ( owner , repo , false , env ) ;
347360
348361 // Fetch the documentation - pass env
349- const docResult = await fetchDocumentation ( { repoData, env } ) ;
362+ const docResult = await fetchDocumentation ( { repoData, env, ctx } ) ;
350363 const content = docResult . content [ 0 ] . text ;
351364 const fileUsed = docResult . fileUsed ;
352365
0 commit comments