cloudflare-docs icon indicating copy to clipboard operation
cloudflare-docs copied to clipboard

Add empty and null check for the vefctorQuery.matches[0], output nece…

Open xqliu opened this issue 1 year ago • 0 comments

…ssary log

Summary

Build a Retrieval Augmented Generation (RAG) AI doc

Screenshots (optional)

If no such null check, it will shows follow error when no match in the Vectorize index was found.

URL: http://localhost:8787/?text=What%27s%20the%20best%20pizza Screenshot:

image

Text: TypeError: Cannot read properties of undefined (reading 'id')

Which was caused by the follow line

   const vecId = vectorQuery.matches[0].id

Documentation checklist

  • [ ] The documentation style guide has been adhered to.
  • [ ] If a larger change - such as adding a new page- an issue has been opened in relation to any incorrect or out of date information that this PR fixes.
  • [ ] Files which have changed name or location have been allocated redirects.

xqliu avatar Oct 10 '24 23:10 xqliu