firebase / genkit

An open source framework for building AI-powered apps with familiar code-centric patterns. Genkit makes it easy to develop, integrate, and test AI features with observability and evaluations. Genkit works with various models and platforms.
Apache License 2.0
802 stars 121 forks source link

FAILED_PRECONDITION Error with RAG Implementation #343

Closed JGSolutions closed 3 months ago

JGSolutions commented 5 months ago

Describe the bug Implementing a semantic search for board games using Firestore and the RAG implementation with the retriever based from this article https://firebase.google.com/docs/genkit/plugins/firebase

I did generate vector embeddings for 60K for the Firestore documents and defined a Flow (as below). When I increase the limit in the retrieve method I always get this error: FAILED_PRECONDITION: Generation resulted in no candidates matching provided output schema.

If I submit the same prompt with a limit of 5 instead, it works as expected.

To Reproduce

export const boardGameSuggestionFlow = defineFlow(
    {
        name: "boardGameSuggestionFlow",
        inputSchema: z.string(),
        outputSchema: GamesFlowOutput,
    },
    async (query: string) => {
        const docs = await retrieve({
            retriever: retrieverRef,
            query,
            options: {
                limit: 30, ---> This value always getting an error. If set to 5 it works
            },
        });

        const promptDot = await prompt("boardGameSuggestion");
        const result = await promptDot.generate({
            input: {
                query,
            },
            context: docs, // i always get docs response no matter what prompt i request
        });

        const { games } = result.output() as { games: Games[] };

        return games;
    }
);

Expected behavior Just get the results as expected with the same query

Runtime (please complete the following information):

** Node version

Additional context How does the generate() and LLMs work? Also takes a very long time to get a response. Is there a way to increase performance?

JGSolutions commented 5 months ago

Another question about setting the contentField property in the retriever.

Can i combine text into one field. For example i have 3 fields: category, mechanics and description and created a new field called 'content' that combined these 3 fields into one paragraph. Which I created a vector embedding based on this field.

JGSolutions commented 5 months ago

Another question: Do i need to manipulate the docs data to certain type of object of the LLM to understand better?

cabljac commented 5 months ago

~Hey, what did you increase the limit to, to get the error? There is a limit of 1000 in firestore but presumably this error happened with fewer than 1000?~ I see you used 30 in your code

cabljac commented 5 months ago

Can you share your prompt, and your genkit config? In particular what model are you using?

It seems maybe the large context is confusing the model a bit, and it's unable to produce a response in the output format you requested.

cabljac commented 3 months ago

Closing this as stale for now, feel free to reopen if this is still an issue.