-
Notifications
You must be signed in to change notification settings - Fork 67
feat: vectorize #177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: vectorize #177
Conversation
d374cd8
to
df6a752
Compare
commit: |
69f60a0
to
b2ee77b
Compare
Turns out Vectorize doesn't support local development, only with wrangler with --remote. This is unlike Workers AI, which supports local development, however models are actually ran on Cloudflare with your account. Issue tracking Vectorize local bindings: cloudflare/workers-sdk#4360 For now, this feature could only be supported with --remote (either via NuxtHub's proxy or wrangler remote). This would involve adding Vectorize to endpoints to NuxtHub's backend and I don't think that's OSS. Alternatively it could be blocked until local development is supported with Vectorize. Alternatively, t |
Thanks for looking at it so quickly. I think this could anyway be possible within the OSS as you would need to deploy your application at first in order to use Vectorize. Would you be happy to work on the proxy API routes? |
0f12411
to
8672867
Compare
I didn't realise those routes were for anything more than just devtools preview with --remote for some reason lol 😄 I've added the proxy routes, I'll continue my dissertation where I'll be testing test both AI and Vectorize integrations to build a simple vector search engine. |
6173476
to
aedb7c2
Compare
afb114f
to
95cf814
Compare
95cf814
to
b890979
Compare
45 minutes of rebasing 😓 git is not my passion |
Co-authored-by: Sébastien Chopin <[email protected]>
Closes #174, Related #173
Adds support for using Vectorize indexes.
For docs: Vectorize through Cloudflare bindings accessed via
const vectorize = hubVectorize(<index>)
so their docs apply. https://developers.cloudflare.com/vectorize/reference/client-api/How to use now?
While vector databases is still a wip PR, using it is pretty straightforward to use now and if you're fine with temporary caveats like manually adding bindings to environments, and developing via --remote then you can use it today. There may be breaking changes, so review when updating @nuxt-hub/core.
1. Create Index
You'll currently need to manually create a binding via
wrangler
while this PR is still in progress. This will eventually be handled by Nuxt Hub while deploying.An index's dimensions and metrics should be set based on the embeddings model you're using. I'm using
bge-base-en-v1.5
, which needs 768/cosine. You cannot change this later without recreating the index (and triggering a new Pages deployment)Once you've made the index , you can add a binding for it via the Cloudflare dash (Pages -> Settings -> Functions Vectorize index bindings).

Update: Make sure the binding name follows this format:
VECTORIZE_<index name in upper case>
. In this scenario it'd beVECTORIZE_PRODUCTS
.2. Use
@nuxt-hub/core
version built from this PR3. Enable Vectorize
4. Deploy the website
As --remote is required because Cloudflare doesn't support local Vectorize bindings yet, you'll need to push and deploy now so we can use Vectorize via bindings on the deployed application.
5. Done!
You need to use --remote for now.
Docs
What are vector databases for?
Read https://developers.cloudflare.com/vectorize/reference/what-is-a-vector-database/
Usage
See operations here https://developers.cloudflare.com/vectorize/reference/client-api/#operations
Usage example
Querying
In this example, 1. a vector is generated from the query, 2. search is via Vectorize, 3. then data is enriched by querying the database. https://developers.cloudflare.com/vectorize/reference/what-is-a-vector-database/#vector-search
If you wanted to build a RAG experience, you'd have a 4th step where you pass all this information to an LLM as context in a prompt. See https://developers.cloudflare.com/workers-ai/tutorials/build-a-retrieval-augmented-generation-ai/
Code
Bulk vector generation and import
This example bulk generates and imports vectors for items in a database using a text embeddings model to create search experience.
Code
Vectorize supports upserting 1000 via the Workers API and 5000 via the HTTP API currently, so it's unlikely that the looping for batches is necessary, however, I ran into some issues before which I didn't have time to debug so I made the chunks smaller.
You can likely simplify this code a lot, but it's a starting point.
More
It's possible to store core data in Vectorize directly as metadata on the record. If you fetch from Vectorize with metadata or values, you're limited to the top 30 results. If you only want to get IDs and match % back, you can get the top 100 results. (https://developers.cloudflare.com/vectorize/platform/limits/)