|
| 1 | +--- |
| 2 | +--- |
| 3 | + |
| 4 | +# Google Generative AI |
| 5 | + |
| 6 | +import Tabs from '@theme/Tabs'; |
| 7 | +import TabItem from '@theme/TabItem'; |
| 8 | + |
| 9 | +<div class="select-language">Select a language</div> |
| 10 | + |
| 11 | +<Tabs queryString groupId="lang"> |
| 12 | +<TabItem value="py" label="Python"></TabItem> |
| 13 | +<TabItem value="js" label="JavaScript"></TabItem> |
| 14 | +</Tabs> |
| 15 | + |
| 16 | +Chroma provides a convenient wrapper around Google's Generative AI embedding API. This embedding function runs remotely on Google's servers, and requires an API key. |
| 17 | + |
| 18 | +You can get an API key by signing up for an account at [Google MakerSuite](https://makersuite.google.com/). |
| 19 | + |
| 20 | +<Tabs queryString groupId="lang" className="hideTabSwitcher"> |
| 21 | +<TabItem value="py" label="Python"> |
| 22 | + |
| 23 | +This embedding function relies on the `google-generativeai` python package, which you can install with `pip install google-generativeai`. |
| 24 | + |
| 25 | +```python |
| 26 | +# import |
| 27 | +import chromadb |
| 28 | +from chromadb.utils import embedding_functions |
| 29 | + |
| 30 | +# use directly |
| 31 | +google_ef = embedding_functions.GoogleGenerativeAiEmbeddingFunction(api_key="YOUR_API_KEY") |
| 32 | +google_ef(["document1","document2"]) |
| 33 | + |
| 34 | +# pass documents to query for .add and .query |
| 35 | +collection = client.create_collection(name="name", embedding_function=google_ef) |
| 36 | +collection = client.get_collection(name="name", embedding_function=google_ef) |
| 37 | +``` |
| 38 | + |
| 39 | +You can view a more [complete example](https://github.com/chroma-core/chroma/tree/main/examples/gemini) chatting over documents with Gemini embedding and langauge models. |
| 40 | + |
| 41 | +For more info - please visit the [official Google python docs](https://ai.google.dev/tutorials/python_quickstart). |
| 42 | + |
| 43 | +</TabItem> |
| 44 | +<TabItem value="js" label="JavaScript"> |
| 45 | + |
| 46 | +This embedding function relies on the `@google/generative-ai` npm package, which you can install with `yarn add @google/generative-ai`. |
| 47 | + |
| 48 | +```javascript |
| 49 | +import { ChromaClient, GoogleGenerativeAiEmbeddingFunction } from 'chromadb' |
| 50 | +const embedder = new GoogleGenerativeAiEmbeddingFunction({googleApiKey: "<YOUR API KEY>"}) |
| 51 | + |
| 52 | +// use directly |
| 53 | +const embeddings = await embedder.generate(["document1","document2"]) |
| 54 | + |
| 55 | +// pass documents to query for .add and .query |
| 56 | +const collection = await client.createCollection({name: "name", embeddingFunction: embedder}) |
| 57 | +const collectionGet = await client.getCollection({name:"name", embeddingFunction: embedder}) |
| 58 | +``` |
| 59 | + |
| 60 | +You can view a more [complete example using Node](https://github.com/chroma-core/chroma/blob/main/clients/js/examples/node/app.js). |
| 61 | + |
| 62 | +For more info - please visit the [official Google JS docs](https://ai.google.dev/tutorials/node_quickstart). |
| 63 | + |
| 64 | +</TabItem> |
| 65 | + |
| 66 | +</Tabs> |
| 67 | + |
0 commit comments