Skip to content

Commit

Permalink
Update getting-started.md
Browse files Browse the repository at this point in the history
Add embeddingFunction parameter to getOrCreateCollection function
  • Loading branch information
atthar2 authored Jan 7, 2025
1 parent df4fea1 commit 239c0be
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,25 @@ print(results)

{% Tab label="typescript" %}
```typescript
import { ChromaClient } from "chromadb";
import { ChromaClient, OpenAIEmbeddingFunction, OllamaEmbeddingFunction } from "chromadb";

// using OpenAI mmbedding
const embedder = new OpenAIEmbeddingFunction({
openai_api_key: "your_api_key",
});

// using ollama embedding
const embedder = new OllamaEmbeddingFunction({
url: "http://127.0.0.1:11434/api/embeddings",
model: "llama2"
})

const client = new ChromaClient();

// switch `createCollection` to `getOrCreateCollection` to avoid creating a new collection every time
const collection = await client.getOrCreateCollection({
name: "my_collection",
embeddingFunction: embedder,
});

// switch `addRecords` to `upsertRecords` to avoid adding the same documents every time
Expand Down

0 comments on commit 239c0be

Please sign in to comment.