Skip to content

Commit d23953f

Browse files
committed
feat: Added Ollama Integration
1 parent 22c6c25 commit d23953f

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Ollama
2+
3+
First let's run a local docker container with Ollama. We'll pull `nomic-embed-text` model:
4+
5+
```bash
6+
docker run -d -v ./ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama
7+
docker exec -it ollama ollama run nomic-embed-text # press Ctrl+D to exit after model downloads successfully
8+
# test it
9+
curl http://localhost:11434/api/embeddings -d '{"model": "nomic-embed-text","prompt": "Here is an article about llamas..."}'
10+
```
11+
12+
!!! note "Ollama Docs"
13+
14+
For more information on Ollama, visit the [Ollama GitHub repository](https://github.com/ollama/ollama).
15+
16+
Now let's configure our OllamaEmbeddingFunction Embedding (python) function with the default Ollama endpoint:
17+
18+
```python
19+
import chromadb
20+
from chromadb.utils.embedding_functions import OllamaEmbeddingFunction
21+
22+
client = chromadb.PersistentClient(path="ollama")
23+
24+
# create EF with custom endpoint
25+
ef = OllamaEmbeddingFunction(
26+
model_name="nomic-embed-text",
27+
url="http://localhost:11434/api/embeddings",
28+
)
29+
30+
print(ef(["Here is an article about llamas..."]))
31+
```
32+
33+
For JS users, you can use the `OllamaEmbeddingFunction` class to create embeddings:
34+
35+
```javascript
36+
const {OllamaEmbeddingFunction} = require('chromadb');
37+
const embedder = new OllamaEmbeddingFunction({
38+
url: "http://localhost:11434/api/embeddings",
39+
model: "nomic-embed-text"
40+
})
41+
42+
// use directly
43+
const embeddings = embedder.generate(["Here is an article about llamas..."])
44+
```
45+
46+
For Golang you can use the `chroma-go` client's `OllamaEmbeddingFunction` embedding function to generate embeddings for
47+
your documents:
48+
49+
```go
50+
package main
51+
52+
import (
53+
"context"
54+
"fmt"
55+
ollama "github.com/amikos-tech/chroma-go/ollama"
56+
)
57+
58+
func main() {
59+
documents := []string{
60+
"Document 1 content here",
61+
"Document 2 content here",
62+
}
63+
// the `/api/embeddings` endpoint is automatically appended to the base URL
64+
ef, err := ollama.NewOllamaEmbeddingFunction(ollama.WithBaseURL("http://127.0.0.1:11434"), ollama.WithModel("nomic-embed-text"))
65+
if err != nil {
66+
fmt.Printf("Error creating Ollama embedding function: %s \n", err)
67+
}
68+
resp, err := ef.EmbedDocuments(context.Background(), documents)
69+
if err != nil {
70+
fmt.Printf("Error embedding documents: %s \n", err)
71+
}
72+
fmt.Printf("Embedding response: %v \n", resp)
73+
}
74+
```
75+
76+
!!! note "Golang Client"
77+
78+
You can install the Golang client by running the following command:
79+
80+
```bash
81+
go get github.com/amikos-tech/chroma-go
82+
```
83+
84+
For more information visit [https://go-client.chromadb.dev/](https://go-client.chromadb.dev/)

0 commit comments

Comments
 (0)