Skip to content

Commit d444c11

Browse files
RihanArfanatinuxleomp12HugoRCDrenovate[bot]
authored
feat: autorag (#541)
Co-authored-by: Sébastien Chopin <[email protected]> Co-authored-by: Sébastien Chopin <[email protected]> Co-authored-by: Leonardo Matos <[email protected]> Co-authored-by: Hugo Richard <[email protected]> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
1 parent f75f708 commit d444c11

File tree

16 files changed

+705
-66
lines changed

16 files changed

+705
-66
lines changed

docs/content/changelog/hub-autorag.md

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
title: Introducing hubAutoRAG()
3+
description: "Create fully-managed RAG pipelines to power your AI applications with accurate and up-to-date information."
4+
date: 2025-05-06
5+
image: '/images/changelog/nuxthub-autorag.png'
6+
authors:
7+
- name: Rihan Arfan
8+
avatar:
9+
src: https://avatars.githubusercontent.com/u/20425781?v=4
10+
to: https://bsky.app/profile/rihan.dev
11+
username: rihan.dev
12+
---
13+
14+
::tip
15+
This feature is available from [`@nuxthub/core >= v0.8.26`](https://github.com/nuxt-hub/core/releases/tag/v0.8.26)
16+
::
17+
18+
19+
We are excited to introduce [`hubAutoRAG()`](/docs/features/autorag). Cloudflare [AutoRAG](https://developers.cloudflare.com/autorag/) lets you create fully-managed, retrieval-augmented generation pipelines that continuously updates and scales on Cloudflare. With AutoRAG, you can integrate context-aware AI into your Nuxt applications without managing infrastructure.
20+
21+
If you are currently using [`hubVectorize()`](/docs/features/vectorize), you may be interested in switching to `hubAutoRAG()` for a simplified developer experience. AutoRAG automatically indexes your data into vector embeddings optimized for semantic search. Once a data source is connected, indexing runs continuously in the background to keep your knowledge base fresh and queryable.
22+
23+
## How to use hubAutoRAG()
24+
25+
1. Update `@nuxthub/core` to the latest version (`v0.8.26` or later)
26+
27+
2. Enable `hub.ai` in your `nuxt.config.ts`
28+
29+
```ts [nuxt.config.ts]
30+
export default defineNuxtConfig({
31+
hub: {
32+
ai: true
33+
}
34+
})
35+
```
36+
37+
3. Create an AutoRAG instance from the [Cloudflare dashboard](https://dash.cloudflare.com/?to=/:account/ai/autorag) and add your data source.
38+
39+
::callout{to="https://dash.cloudflare.com/?to=/:account/ai/autorag"}
40+
Go to [AutoRAG](https://dash.cloudflare.com/?to=/:account/ai/autorag) in the [Cloudflare dashboard](https://dash.cloudflare.com/?to=/:account/ai/autorag)
41+
::
42+
43+
4. Start using [`hubAutoRAG()`](/docs/features/browser) in your server routes
44+
45+
```ts [server/api/rag.ts]
46+
export default eventHandler(async () => {
47+
const autorag = hubAutoRAG("nuxt-ui") // access AutoRAG instance
48+
return await autorag.aiSearch({
49+
query: "How do I create a modal with Nuxt UI?",
50+
model: "@cf/meta/llama-3.3-70b-instruct-sd",
51+
rewrite_query: true,
52+
max_num_results: 2,
53+
ranking_options: {
54+
score_threshold: 0.7,
55+
},
56+
})
57+
})
58+
```
59+
60+
5. [Deploy your project with NuxtHub](/docs/getting-started/deploy)
61+
62+
::note{to="/docs/features/autorag"}
63+
Read the documentation about `hubAutoRAG()` to learn more.
64+
::

docs/content/docs/2.features/ai.md

+54-15
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ const response = await hubAI().run('@cf/runwayml/stable-diffusion-v1-5-img2img',
2222

2323
```ts [embeddings.ts]
2424
// returns embeddings that can be used for vector searches in tools like Vectorize
25-
const embeddings = await hubAI().run("@cf/baai/bge-base-en-v1.5", {
26-
text: "NuxtHub AI uses `hubAI()` to run models."
25+
const embeddings = await hubAI().run("@cf/baai/bge-base-en-v1.5", {
26+
text: "NuxtHub AI uses `hubAI()` to run models."
2727
});
2828
```
2929
::
@@ -100,16 +100,55 @@ export default defineEventHandler(async () => {
100100
::
101101

102102
::field{name="AI Gateway" type="object"}
103-
Options for configuring [`AI Gateway`](#ai-gateway) - `id`, `skipCache`, and `cacheTtl`.
103+
Options for configuring [`AI Gateway`](#ai-gateway) - `id`, `skipCache`, and `cacheTtl`.
104104
::
105105
::
106106

107+
### `models()`
108+
109+
List all available models programatically.
110+
111+
```ts [server/api/models-test.ts]
112+
export default defineEventHandler(async () => {
113+
const ai = hubAI() // access AI bindings
114+
return await ai.models({ page: 2 })
115+
})
116+
```
117+
118+
#### Options
119+
120+
::field-group
121+
::field{name="params" type="object"}
122+
::collapsible
123+
::field{name="author" type="string"}
124+
The author of the model to filter by.
125+
126+
::field{name="hide_experimental" type="boolean"}
127+
Whether to hide experimental models.
128+
129+
::field{name="page" type="number"}
130+
The page of results to return.
131+
132+
::field{name="per_page" type="number"}
133+
The number of results to return per page.
134+
135+
::field{name="search" type="string"}
136+
A search term to filter models by.
137+
138+
::field{name="source" type="number"}
139+
The source ID to filter by.
140+
141+
::field{name="task" type="string"}
142+
The task name to filter by.
143+
::
144+
::
145+
::
107146

108147
## Tools
109148

110-
Tools are actions that your LLM can execute to run functions or interact with external APIs. The result of these tools will be used by the LLM to generate additional responses.
149+
Tools are actions that your LLM can execute to run functions or interact with external APIs. The result of these tools will be used by the LLM to generate additional responses.
111150

112-
This can help you supply the LLM with real-time information, save data to a KV store, or provide it with external data from your database.
151+
This can help you supply the LLM with real-time information, save data to a KV store, or provide it with external data from your database.
113152

114153
With Workers AI, tools have 4 properties:
115154
- `name`: The name of the tool
@@ -125,7 +164,7 @@ const tools = [
125164
parameters: {
126165
type: 'object',
127166
properties: {
128-
city: {
167+
city: {
129168
type: 'number',
130169
description: 'The city to retrieve weather information for'
131170
},
@@ -152,7 +191,7 @@ const tools = [
152191
::
153192

154193
::field{name="parameters" type="JsonSchema7"}
155-
The parameters and options for parameters that the model will use to run the tool.
194+
The parameters and options for parameters that the model will use to run the tool.
156195
::collapsible
157196
::field{name="type" type="string"}
158197
The type of your functions parameter. It's recommended to use an `object` so you can easily add additional properties in the future.
@@ -189,7 +228,7 @@ npx nypm i @cloudflare/ai-utils
189228
import { runWithTools } from '@cloudflare/ai-utils'
190229

191230
export default defineEventHandler(async (event) => {
192-
return await runWithTools(hubAI(), '@cf/meta/llama-3.1-8b-instruct',
231+
return await runWithTools(hubAI(), '@cf/meta/llama-3.1-8b-instruct',
193232
{
194233
messages: [
195234
{ role: 'user', content: 'What is the weather in New York?' },
@@ -201,8 +240,8 @@ export default defineEventHandler(async (event) => {
201240
parameters: {
202241
type: 'object',
203242
properties: {
204-
city: {
205-
type: 'number',
243+
city: {
244+
type: 'number',
206245
description: 'The city to retrieve weather information for'
207246
},
208247
},
@@ -214,7 +253,7 @@ export default defineEventHandler(async (event) => {
214253
},
215254
},
216255
]
217-
},
256+
},
218257
{
219258
// options
220259
streamFinalResponse: true,
@@ -300,7 +339,7 @@ export default defineEventHandler(async () => {
300339
::
301340

302341
::field{name="cacheTtl" type="number"}
303-
Controls the [Cache TTL](https://developers.cloudflare.com/ai-gateway/configuration/caching/#cache-ttl-cf-cache-ttl), the duration (in seconds) that a cached request will be valid for. The minimum TTL is 60 seconds and maximum is one month.
342+
Controls the [Cache TTL](https://developers.cloudflare.com/ai-gateway/configuration/caching/#cache-ttl-cf-cache-ttl), the duration (in seconds) that a cached request will be valid for. The minimum TTL is 60 seconds and maximum is one month.
304343
::
305344
::
306345

@@ -310,7 +349,7 @@ The recommended method to handle text generation responses is streaming.
310349

311350
LLMs work internally by generating responses sequentially using a process of repeated inference — the full output of a LLM model is essentially a sequence of hundreds or thousands of individual prediction tasks. For this reason, while it only takes a few milliseconds to generate a single token, generating the full response takes longer.
312351

313-
If your UI waits for the entire response to be generated, a user may see a loading spinner for several seconds before the response is displayed.
352+
If your UI waits for the entire response to be generated, a user may see a loading spinner for several seconds before the response is displayed.
314353

315354
Streaming lets you start displaying the response as soon as the first tokens are generated, and append each additional token until the response is complete. This yields a much better experience for the end user. Displaying text incrementally as it’s generated not only provides instant responsiveness, but also gives the end-user time to read and interpret the text.
316355

@@ -386,7 +425,7 @@ npx nypm i ai @ai-sdk/vue workers-ai-provider
386425

387426
### `useChat()`
388427

389-
`useChat()` is a Vue composable provided by the Vercel AI SDK that handles streaming responses, API calls, state for your chat.
428+
`useChat()` is a Vue composable provided by the Vercel AI SDK that handles streaming responses, API calls, state for your chat.
390429

391430
It requires a `POST /api/chat` endpoint that uses the `hubAI()` server composable and returns a compatible stream for the Vercel AI SDK.
392431

@@ -457,6 +496,6 @@ Explore open source templates made by the community:
457496
::
458497

459498

460-
## Pricing
499+
## Pricing
461500

462501
:pricing-table{:tabs='["AI"]'}

0 commit comments

Comments
 (0)