Introducing hubVectorize()
@nuxthub/core >= v0.7.24
.We are excited to introduce hubVectorize()
, which gives you access to a globally distributed vector database from Nuxt. Paired with hubAI()
, it makes Nuxt a perfect framework for easily building full-stack AI-powered applications.
What is a vector database?
Vector databases allows you to querying embeddings, which are representations of values or objects like text, images, audio that are designed to be consumed by machine learning models and semantic search algorithms.
Some key use cases of vector databases include:
- Semantic search, used to return results similar to the input of the query.
- Classification, used to return the grouping (or groupings) closest to the input query.
- Recommendation engines, used to return content similar to the input based on different criteria (for example previous product sales, or user history).
Vector databases are commonly used for Retrieval-Augmented Generation (RAG), which is a technique that enhances language models by retrieving relevant information from an external knowledge base before generating a response.
Learn more about vector databases on Cloudflare's documentation.
How to use hubVectorize()
- Update
@nuxthub/core
to the latest version (v0.7.24
or later) - Configure a Vectorize index in
hub.vectorize
in yournuxt.config.ts
export default defineNuxtConfig({
hub: {
vectorize: {
tutorial: {
dimensions: 768,
metric: "cosine"
}
}
}
})
- Run
npx nuxthub link
to link a NuxtHub project or create a new one - Deploy the project to NuxtHub with
npx nuxthub deploy
- Start Nuxt and connect to remote storage by running
npx nuxt dev --remote
- You can now use
hubVectorize('<index>')
in your server routes
export default defineEventHandler(async (event) => {
const { query, limit } = getQuery(event)
const embeddings = await hubAI().run('@cf/baai/bge-base-en-v1.5', {
text: query
})
const queryVector = embeddings.data[0]
const index = hubVectorize('tutorial')
return await vectorize.query(vectors, {
topK: limit,
})
})
Read the full documentation to learn more about hubVectorize()
.
Vectorize
permission on your Cloudflare API token.- Open Cloudflare User API Tokens
- Find the NuxtHub token(s)
- Add the
Account > Vectorize > Edit
permission - Save the changes
Link a new account
> Create a token with required permissions
.