Skip to content
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

fix: rag doc updates #1677

Merged
merged 3 commits into from
Jan 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() },
ssbushi marked this conversation as resolved.
Show resolved Hide resolved
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"'
ssbushi marked this conversation as resolved.
Show resolved Hide resolved
```

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