Skip to content

Commit 32910f9

Browse files
authored
Add empty and null check for the vefctorQuery.matches[0], output necessary log
1 parent 6db4636 commit 32910f9

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/content/docs/workers-ai/tutorials/build-a-retrieval-augmented-generation-ai.mdx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,12 @@ app.get('/', async (c) => {
287287
const vectors = embeddings.data[0]
288288

289289
const vectorQuery = await c.env.VECTOR_INDEX.query(vectors, { topK: 1 });
290-
const vecId = vectorQuery.matches[0].id
290+
let vecId;
291+
if (vectorQuery.matches && vectorQuery.matches.length > 0 && vectorQuery.matches[0]) {
292+
vecId = vectorQuery.matches[0].id;
293+
} else {
294+
console.log("No matching vector found or vectorQuery.matches is empty");
295+
}
291296

292297
let notes = []
293298
if (vecId) {

0 commit comments

Comments
 (0)