From c87f3a5ec7664261da80812de7de0700a5177fae Mon Sep 17 00:00:00 2001 From: Samuel Bushi <ssbushi@google.com> Date: Tue, 28 Jan 2025 21:27:31 +0000 Subject: [PATCH 1/3] fix: rag doc updates --- docs/rag.md | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/rag.md b/docs/rag.md index 4176da66f..e8fbb4e9a 100644 --- a/docs/rag.md +++ b/docs/rag.md @@ -226,12 +226,12 @@ export const indexMenu = ai.defineFlow( filePath = path.resolve(filePath); // Read the pdf. - const pdfTxt = await run('extract-text', () => + const pdfTxt = await ai.run('extract-text', () => extractTextFromPdf(filePath) ); // Divide the pdf text into segments. - const chunks = await run('chunk-it', async () => + const chunks = await ai.run('chunk-it', async () => chunk(pdfTxt, chunkingConfig) ); @@ -266,12 +266,13 @@ which you should not use in production. ```ts import { devLocalRetrieverRef } from '@genkit-ai/dev-local-vectorstore'; +import { gemini15Flash } from '@genkit-ai/vertexai'; // Define the retriever reference export const menuRetriever = devLocalRetrieverRef('menuQA'); export const menuQAFlow = ai.defineFlow( - { name: 'menuQA', inputSchema: z.string(), outputSchema: z.string() }, + { name: "menuQA", inputSchema: z.string(), outputSchema: z.string() }, async (input: string) => { // retrieve relevant documents const docs = await ai.retrieve({ @@ -282,6 +283,7 @@ export const menuQAFlow = ai.defineFlow( // generate a response const { text } = await ai.generate({ + model: gemini15Flash, prompt: ` You are acting as a helpful AI assistant that can answer questions about the food available on the menu at Genkit Grub Pub. @@ -299,6 +301,15 @@ Question: ${input}`, ); ``` +#### Run the retriever flow + +```posix-terminal +genkit flow:run menuQA '"Recommend a dessert from the menu while avoiding dairy and nuts"' +``` + +The output for this command should contain a response from the model, grounded +in the indexed `menu.pdf` file. + ## Write your own indexers and retrievers It's also possible to create your own retriever. This is useful if your From 166c616826a24c0784a8dd03f53ca8c105f9265b Mon Sep 17 00:00:00 2001 From: ssbushi <66321939+ssbushi@users.noreply.github.com> Date: Wed, 29 Jan 2025 14:46:41 -0500 Subject: [PATCH 2/3] Update docs/rag.md Co-authored-by: Pavel Jbanov <pavelj@google.com> --- docs/rag.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/rag.md b/docs/rag.md index e8fbb4e9a..ffbf462f6 100644 --- a/docs/rag.md +++ b/docs/rag.md @@ -283,7 +283,7 @@ export const menuQAFlow = ai.defineFlow( // generate a response const { text } = await ai.generate({ - model: gemini15Flash, + model: gemini('gemini-1.5-flash'), prompt: ` You are acting as a helpful AI assistant that can answer questions about the food available on the menu at Genkit Grub Pub. From fd2b524abc2e8ecf370ee62d0351cc6a70c666c8 Mon Sep 17 00:00:00 2001 From: ssbushi <66321939+ssbushi@users.noreply.github.com> Date: Wed, 29 Jan 2025 14:46:49 -0500 Subject: [PATCH 3/3] Update docs/rag.md Co-authored-by: Pavel Jbanov <pavelj@google.com> --- docs/rag.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/rag.md b/docs/rag.md index ffbf462f6..80cb878aa 100644 --- a/docs/rag.md +++ b/docs/rag.md @@ -266,7 +266,7 @@ which you should not use in production. ```ts import { devLocalRetrieverRef } from '@genkit-ai/dev-local-vectorstore'; -import { gemini15Flash } from '@genkit-ai/vertexai'; +import { gemini } from '@genkit-ai/vertexai'; // Define the retriever reference export const menuRetriever = devLocalRetrieverRef('menuQA');