From 8b0e0e3cc8a36d6e08b5f9de1e214f4ea4d27af0 Mon Sep 17 00:00:00 2001 From: Marcus Schiesser <mail@marcusschiesser.de> Date: Mon, 22 Apr 2024 11:40:39 +0800 Subject: [PATCH] docs: use dedicated embedding model for ollama (#745) --- .../embeddings/available_embeddings/ollama.md | 14 +++++++++++--- examples/ollama.ts | 4 +++- package.json | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/apps/docs/docs/modules/embeddings/available_embeddings/ollama.md b/apps/docs/docs/modules/embeddings/available_embeddings/ollama.md index e7a699ee8..b9c9122f7 100644 --- a/apps/docs/docs/modules/embeddings/available_embeddings/ollama.md +++ b/apps/docs/docs/modules/embeddings/available_embeddings/ollama.md @@ -1,11 +1,19 @@ # Ollama -To use Ollama embeddings, you need to import `Ollama` from `llamaindex`. +To use Ollama embeddings, you need to import `OllamaEmbedding` from `llamaindex`. + +Note that you need to pull the embedding model first before using it. + +In the example below, we're using the [`nomic-embed-text`](https://ollama.com/library/nomic-embed-text) model, so you have to call: + +```shell +ollama pull nomic-embed-text +``` ```ts -import { Ollama, Settings } from "llamaindex"; +import { OllamaEmbedding, Settings } from "llamaindex"; -Settings.embedModel = new Ollama(); +Settings.embedModel = new OllamaEmbedding({ model: "nomic-embed-text" }); const document = new Document({ text: essay, id_: "essay" }); diff --git a/examples/ollama.ts b/examples/ollama.ts index 745855a8c..f76f4255c 100644 --- a/examples/ollama.ts +++ b/examples/ollama.ts @@ -1,7 +1,9 @@ +import { OllamaEmbedding } from "llamaindex"; import { Ollama } from "llamaindex/llm/ollama"; (async () => { const llm = new Ollama({ model: "llama3" }); + const embedModel = new OllamaEmbedding({ model: "nomic-embed-text" }); { const response = await llm.chat({ messages: [{ content: "Tell me a joke.", role: "user" }], @@ -35,7 +37,7 @@ import { Ollama } from "llamaindex/llm/ollama"; console.log(); // newline } { - const embedding = await llm.getTextEmbedding("Hello world!"); + const embedding = await embedModel.getTextEmbedding("Hello world!"); console.log("Embedding:", embedding); } })(); diff --git a/package.json b/package.json index be9513dff..4156112f9 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "turbo": "^1.13.2", "typescript": "^5.4.5" }, - "packageManager": "pnpm@9.0.4", + "packageManager": "pnpm@9.0.5", "pnpm": { "overrides": { "trim": "1.0.1", -- GitLab