Skip to content

Commit

Permalink
fix: rag doc updates (#1677)
Browse files Browse the repository at this point in the history
---------
Co-authored-by: Pavel Jbanov <[email protected]>
  • Loading branch information
ssbushi authored Jan 30, 2025
1 parent 634ca57 commit a675bb3
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions docs/rag.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);

Expand Down Expand Up @@ -266,12 +266,13 @@ which you should not use in production.

```ts
import { devLocalRetrieverRef } from '@genkit-ai/dev-local-vectorstore';
import { gemini } 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({
Expand All @@ -282,6 +283,7 @@ export const menuQAFlow = ai.defineFlow(

// generate a response
const { text } = await ai.generate({
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.
Expand All @@ -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
Expand Down

0 comments on commit a675bb3

Please sign in to comment.