Skip to content

Commit

Permalink
docs: 0.9 plugin updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinthecheung committed Nov 12, 2024
1 parent 53f6aaa commit edf9c71
Show file tree
Hide file tree
Showing 5 changed files with 247 additions and 325 deletions.
56 changes: 26 additions & 30 deletions docs/plugins/chroma.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Chroma plugin

The Chroma plugin provides indexer and retriever implementatons that use the
The Chroma plugin provides indexer and retriever implementations that use the
[Chroma](https://docs.trychroma.com/) vector database in client/server mode.

## Installation
Expand All @@ -11,77 +11,73 @@ npm i --save genkitx-chromadb

## Configuration

To use this plugin, specify it when you call `configureGenkit()`:
To use this plugin, specify it when you initialize Genkit:

```js
```ts
import { genkit } from 'genkit';
import { chroma } from 'genkitx-chromadb';

export default configureGenkit({
const ai = genkit({
plugins: [
chroma([
{
collectionName: 'bob_collection',
embedder: textEmbeddingGecko,
embedder: textEmbedding004,
},
]),
],
// ...
});
```

You must specify a Chroma collection and the embedding model you want to use. In
You must specify a Chroma collection and the embedding model you want to use. In
addition, there are two optional parameters:

- `clientParams`: If you're not running your Chroma server on the same machine
as your Genkit flow, you need to specify auth options, or you're otherwise not
running a default Chroma server configuration, you can specify a Chroma
[`ChromaClientParams` object](https://docs.trychroma.com/js_reference/Client)
to pass to the Chroma client:
* `clientParams`: If you're not running your Chroma server on the same machine as your Genkit flow, you need to specify auth options, or you're otherwise not running a default Chroma server configuration, you can specify a Chroma <code>[ChromaClientParams object]([https://docs.trychroma.com/js_reference/Client](https://docs.trychroma.com/js_reference/Client))</code> to pass to the Chroma client:

```js
clientParams: {
path: "http://192.168.10.42:8000",
}
```
```ts
clientParams: {
path: "http://192.168.10.42:8000",
}
```

- `embedderOptions`: Use this parameter to pass options to the embedder:
* `embedderOptions`: Use this parameter to pass options to the embedder:

```js
embedderOptions: { taskType: 'RETRIEVAL_DOCUMENT' },
```
```ts
embedderOptions: { taskType: 'RETRIEVAL_DOCUMENT' },
```

## Usage

Import retriever and indexer references like so:

```js
```ts
import { chromaRetrieverRef } from 'genkitx-chromadb';
import { chromaIndexerRef } from 'genkitx-chromadb';
```

Then, pass the references to `retrieve()` and `index()`:
Then, use the references with `ai.retrieve()` and `ai.index()`:

```js
```ts
// To use the index you configured when you loaded the plugin:
let docs = await retrieve({ retriever: chromaRetrieverRef, query });
let docs = await ai.retrieve({ retriever: chromaRetrieverRef, query });
// To specify an index:
export const bobFactsRetriever = chromaRetrieverRef({
collectionName: 'bob-facts',
});
docs = await retrieve({ retriever: bobFactsRetriever, query });
docs = await ai.retrieve({ retriever: bobFactsRetriever, query });
```

```js
```ts
// To use the index you configured when you loaded the plugin:
await index({ indexer: chromaIndexerRef, documents });
await ai.index({ indexer: chromaIndexerRef, documents });
// To specify an index:
export const bobFactsIndexer = chromaIndexerRef({
collectionName: 'bob-facts',
});
await index({ indexer: bobFactsIndexer, documents });
await ai.index({ indexer: bobFactsIndexer, documents });
```

See the [Retrieval-augmented generation](../rag.md) page for a general
See the [Retrieval-augmented generation](../rag) page for a general
discussion on indexers and retrievers.
103 changes: 54 additions & 49 deletions docs/plugins/google-genai.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ npm i --save @genkit-ai/googleai

## Configuration

To use this plugin, specify it when you call `configureGenkit()`:
To use this plugin, specify it when you initialize Genkit:

```js
```ts
import { genkit } from 'genkit';
import { googleAI } from '@genkit-ai/googleai';

export default configureGenkit({
const ai = genkit({
plugins: [googleAI()],
// ...
});
```

Expand All @@ -27,61 +27,48 @@ The plugin requires an API key for the Gemini API, which you can get from

Configure the plugin to use your API key by doing one of the following:

- Set the `GOOGLE_GENAI_API_KEY` environment variable to your API key.
* Set the `GOOGLE_GENAI_API_KEY` environment variable to your API key.
* Specify the API key when you initialize the plugin:

- Specify the API key when you initialize the plugin:

```js
googleAI({ apiKey: yourKey });
```

However, don't embed your API key directly in code! Use this feature only
in conjunction with a service like Cloud Secret Manager or similar.

Some models (like Gemini 1.5 Pro) are in preview and only aviable via the
`v1beta` API. You can specify the `apiVersion` to get access to those models:

```js
configureGenkit({
plugins: [googleAI({ apiVersion: 'v1beta' })],
});
```ts
googleAI({ apiKey: yourKey });
```

or you can specify multiple versions if you'd like to use different versions of
models at the same time.

```js
configureGenkit({
plugins: [googleAI({ apiVersion: ['v1', 'v1beta'] })],
});
```
However, don't embed your API key directly in code! Use this feature only in
conjunction with a service like Cloud Secret Manager or similar.

## Usage

This plugin statically exports references to its supported models:

```js
```ts
import {
gemini15Flash,
gemini15Pro,
textEmbeddingGecko001,
textEmbedding004,
} from '@genkit-ai/googleai';
```

You can use these references to specify which model `generate()` uses:

```js
const llmResponse = await generate({
```ts
const ai = genkit({
plugins: [googleAI()],
model: gemini15Flash,
prompt: 'Tell me a joke.',
});

const llmResponse = await ai.generate('Tell me a joke.');
```

or use embedders (ex. `textEmbeddingGecko001`) with `embed` or retrievers:
or use embedders (ex. `textEmbedding004`) with `embed` or retrievers:

```ts
const ai = genkit({
plugins: [googleAI()],
});

```js
const embedding = await embed({
embedder: textEmbeddingGecko001,
const embedding = await ai.embed({
embedder: textEmbedding004,
content: input,
});
```
Expand All @@ -90,8 +77,14 @@ const embedding = await embed({

You can use files uploaded to the Gemini Files API with Genkit:

```js
```ts
import { GoogleAIFileManager } from '@google/generative-ai/server';
import { genkit } from 'genkit';
import { googleAI } from '@genkit-ai/googleai';

const ai = genkit({
plugins: [googleAI()],
});

const fileManager = new GoogleAIFileManager(process.env.GOOGLE_GENAI_API_KEY);
const uploadResult = await fileManager.uploadFile(
Expand All @@ -102,7 +95,7 @@ const uploadResult = await fileManager.uploadFile(
}
);

const response = await generate({
const response = await ai.generate({
model: gemini15Flash,
prompt: [
{text: 'Describe this image:'},
Expand All @@ -113,18 +106,30 @@ const response = await generate({

## Fine-tuned models

You can use models fine-tuned with the Google Gemini API. Follow the instructions from the [Gemini API](https://ai.google.dev/gemini-api/docs/model-tuning/tutorial?lang=python) or fine-tune a model using [AI Studio](https://aistudio.corp.google.com/app/tune).
You can use models fine-tuned with the Google Gemini API. Follow the
instructions from the
[Gemini API](https://ai.google.dev/gemini-api/docs/model-tuning/tutorial?lang=python)
or fine-tune a model using
[AI Studio](https://aistudio.corp.google.com/app/tune).

The tuning process uses a base model&mdash;for example, Gemini 1.5 Flash&mdash;and your provided examples to create a new tuned model. Remember the base model you used, and copy the new model's ID.
The tuning process uses a base model—for example, Gemini 1.5 Flash—and your
provided examples to create a new tuned model. Remember the base model you
used, and copy the new model's ID.

When calling the tuned model in Genkit, use the base model as the `model` parameter, and pass the tuned model's ID as part of the `config` block. For example, if you used Gemini 1.5 Flash as the base model, and got the model ID `tunedModels/my-example-model-apbm8oqbvuv2` you can call it with a block like the following:
When calling the tuned model in Genkit, use the base model as the `model`
parameter, and pass the tuned model's ID as part of the `config` block. For
example, if you used Gemini 1.5 Flash as the base model, and got the model ID
`tunedModels/my-example-model-apbm8oqbvuv2` you can call it with:

```js
const llmResponse = await generate({
```ts
const ai = genkit({
plugins: [googleAI()],
});

const llmResponse = await ai.generate({
prompt: `Suggest an item for the menu of fish themed restruant`,
model: gemini15Flash,
config: {
model: gemini15Flash.withConfig({
version: "tunedModels/my-example-model-apbm8oqbvuv2",
},
}),
});
```
```
Loading

0 comments on commit edf9c71

Please sign in to comment.