Skip to content

Commit

Permalink
docs: add embedding model doc in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jeasonstudio committed Jul 4, 2024
1 parent b053e5f commit f813465
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@ You can use the following optional settings to customize:
- **temperature** `number` (default: `0.8`)
- **topK** `number` (default: `3`)

## Embedding models

```ts
import { chromeai } from 'chrome-ai';
import { embedMany, cosineSimilarity } from 'ai';

const { embeddings } = await embedMany({
model: chromeai.embedding(),
values: ['sunny day at the beach', 'rainy afternoon in the city'],
});
// [[1.9545, 0.0318...], [1.8015, 0.1504...]]

const similarity = cosineSimilarity(embeddings[0], embeddings[1]);
// similarity: 0.9474937159037822
```

## 🎯 Examples

You can use Chrome built-in language models to generate text with the `generateText` or `streamText` function:
Expand Down

0 comments on commit f813465

Please sign in to comment.