Skip to content

Adds defineSimpleRetriever and docs.#125

Merged
mbleigh merged 5 commits into
mainfrom
simpleretriever
May 12, 2024
Merged

Adds defineSimpleRetriever and docs.#125
mbleigh merged 5 commits into
mainfrom
simpleretriever

Conversation

@mbleigh
Copy link
Copy Markdown
Collaborator

@mbleigh mbleigh commented May 11, 2024

Building out my demo I found it kind of annoying to write a retriever because converting things into Documents is tedious. This provides a "simple retriever" that makes it very easy to transform arbitrary data into documents. For example, here is the Data Connect retriever from my demo implemented as a simple retriever:

export const destinationRetriever = defineSimpleRetriever(
  {
    name: 'destinationRetriever',
    configSchema: z.object({ limit: z.number() }),
    content: 'knownFor',
  },
  async (query, { limit }) => {
    const result = await searchDestinations(dc, {
      query: query.text(),
      limit: limit,
    });
    return result.data.destinations;
  },
);

Pretty nice, right?

Comment thread docs/rag.md Outdated
Comment thread js/ai/src/retriever.ts
* @param handler A function that queries a datastore and returns items from which to extract documents.
* @returns A Genkit retriever.
*/
export function defineSimpleRetriever<
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is neat and I think it should exist, just wondering if it should exist here... the more I think about it the more I think it's probably OK that it's exported via @genkit-ai/ai/retriever... not sure, just saying it out loud... feel free to ignore.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's the right place for it, but fair to ask.

Co-authored-by: Pavel Jbanov <pavelj@google.com>
@mbleigh mbleigh enabled auto-merge (squash) May 12, 2024 17:24
@mbleigh mbleigh merged commit d557c48 into main May 12, 2024
@mbleigh mbleigh deleted the simpleretriever branch May 12, 2024 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants