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

[Docs] Chroma Plugin example throws exception on retrieve #973

Closed
FriedrichWessel opened this issue Sep 26, 2024 · 0 comments
Closed

[Docs] Chroma Plugin example throws exception on retrieve #973

FriedrichWessel opened this issue Sep 26, 2024 · 0 comments
Assignees
Labels
docs Improvements or additions to documentation

Comments

@FriedrichWessel
Copy link

Based on the documentation for the Chroma Plugin ( https://firebase.google.com/docs/genkit/plugins/chroma )
I created a simple example script for the ChromaPlugin.

Description
The example runs fine when using devLocalndexer / Retriever, but throws an exception when running with a ChromaDB. So there seems to be a crucial information missing on the chromaDB Plugin documentation.

Environment
Hostmachine: MacOS
ChromaServer is running in a docker Container
Embedding and LLM connect to openAI

Behaviour

  • I can add content to the database in the DevUI by running the flow fillDB
  • calling the flow requestDB from DevUi throws an exception:

Exception

Running action `/flow/requestDB`...
{ start: { input: 'are green cars the worst ? ' } } runEnvelope
save flow state 2b7a967c-5dc9-47c7-8aef-caad1dc537e8
Fetching traces for env `dev`.
Fetching trace `43c3efc4410189f919848c36276950ff` for env `dev`.
Fetching flow state `2b7a967c-5dc9-47c7-8aef-caad1dc537e8` for env `dev`.
Fetching actions.
/Users/friedrich.wessel/work/AI-Taskforce/unity-firebase-genkit-template/backend/node_modules/zod-to-json-schema/dist/cjs/parsers/nativeEnum.js:6
    const actualKeys = Object.keys(def.values).filter((key) => {
                              ^

TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at parseNativeEnumDef (/Users/friedrich.wessel/work/AI-Taskforce/unity-firebase-genkit-template/backend/node_modules/zod-to-json-schema/dist/cjs/parsers/nativeEnum.js:6:31)
    at selectParser (/Users/friedrich.wessel/work/AI-Taskforce/unity-firebase-genkit-template/backend/node_modules/zod-to-json-schema/dist/cjs/parseDef.js:119:59)
    at parseDef (/Users/friedrich.wessel/work/AI-Taskforce/unity-firebase-genkit-template/backend/node_modules/zod-to-json-schema/dist/cjs/parseDef.js:52:24)
    at parseArrayDef (/Users/friedrich.wessel/work/AI-Taskforce/unity-firebase-genkit-template/backend/node_modules/zod-to-json-schema/dist/cjs/parsers/array.js:12:48)
    at selectParser (/Users/friedrich.wessel/work/AI-Taskforce/unity-firebase-genkit-template/backend/node_modules/zod-to-json-schema/dist/cjs/parseDef.js:104:49)
    at parseDef (/Users/friedrich.wessel/work/AI-Taskforce/unity-firebase-genkit-template/backend/node_modules/zod-to-json-schema/dist/cjs/parseDef.js:52:24)
    at parseOptionalDef (/Users/friedrich.wessel/work/AI-Taskforce/unity-firebase-genkit-template/backend/node_modules/zod-to-json-schema/dist/cjs/parsers/optional.js:7:43)
    at selectParser (/Users/friedrich.wessel/work/AI-Taskforce/unity-firebase-genkit-template/backend/node_modules/zod-to-json-schema/dist/cjs/parseDef.js:123:55)
    at parseDef (/Users/friedrich.wessel/work/AI-Taskforce/unity-firebase-genkit-template/backend/node_modules/zod-to-json-schema/dist/cjs/parseDef.js:52:24)

Script

import * as dotenv from 'dotenv'
dotenv.config()


import { configureGenkit } from '@genkit-ai/core';
import { defineFlow } from '@genkit-ai/flow';


import { gpt4o, openAI, textEmbedding3Small}  from 'genkitx-openai';
import { Document, index, retrieve } from '@genkit-ai/ai/retriever';
import { chroma, chromaIndexerRef, chromaRetrieverRef } from 'genkitx-chromadb';


import { z } from 'zod';
import { generate } from '@genkit-ai/ai';

configureGenkit({
  plugins: [
    openAI(),
    chroma([
      {
        collectionName: 'example_db',
        embedder: textEmbedding3Small,
        createCollectionIfMissing: true,
        clientParams: {
          path: "http://localhost:8000",
        }
      },
    ])
  ],
  logLevel: 'debug',
  enableTracingAndMetrics: true,
});

export const retriever = chromaRetrieverRef({
  collectionName: 'example_db',
});

export const indexer = chromaIndexerRef({
 collectionName: 'example_db',
});

export const fillDB = defineFlow(
  {
    name: 'fillDB',
    inputSchema: z.string(),
    outputSchema: z.string(),
  },
  async (data) => {
    let doc = Document.fromText(`This is test content about ${data}`);
    const documents = [doc]
    await index({ indexer: indexer, documents })
    return `Added ${data} to the DB`;
  }
);

export const requestDB = defineFlow(
  {
    name: 'requestDB',
    inputSchema: z.string(),
    outputSchema: z.string(),
  },
  async (question) => {
      let options : any =  { k : 3}
      
      const docs = await retrieve({
        retriever: retriever,
        query : question, 
        options,
      });
      
      const llmResponse = await generate( {
        model: gpt4o,
        prompt: `${question}`,
        context: docs
      });
        
      return llmResponse.text();
  }
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to documentation
Projects
Archived in project
Development

No branches or pull requests

3 participants