# 05. OllamaEmbeddings

Ollama is an open source project that makes it easy to run a large language model (LLM) in a local environment. This tool allows you to download and run various LLMs as simple instructions, helping developers experiment and use AI models directly on their computers. Ollama is a user-friendly interface and fast performance, making AI development and experimentation more accessible and efficient.

* [Official website / installation](https://ollama.com/)

Copy

```
texts = [
    "Hello, nice to meet you.",
    "LangChain simplifies the process of building applications with large language models",
    "LangChain Korean Tutorial is the official documentation of LangChain, It is structured to help users utilize LangChain more easily and effectively, based on a cookbook and various practical examples.",
    "LangChain simplifies the process of building applications with large language models.",
    "Retrieval-Augmented Generation (RAG) is an effective technique for improving AI responses.",
]
```

**Check supported embedding models**

* <https://ollama.com/library>

Copy

```
from langchain_community.embeddings import OllamaEmbeddings

ollama_embeddings = OllamaEmbeddings(
    model="nomic-embed-text",
    # model="chatfire/bge-m3:q8_0" # BGE-M3
)
```

`Query` Embed.

Copy

```
# Query embedding
embedded_query = ollama_embeddings.embed_query("LangChain Please tell me more about.")
# Embedding dimension output
len(embedded_query)
```

Copy

```
 768 
```

Embed documents.

Copy

```
# Document Embedding
embedded_documents = ollama_embeddings.embed_documents(texts)
```

Similarity outputs the calculation result.

Copy

```
import numpy as np

# 질문(embedded_query): LangChain Please tell me about.
similarity = np.array(embedded_query) @ np.array(embedded_documents).T

# Sort by descending similarity
sorted_idx = (np.array(embedded_query) @ np.array(embedded_documents).T).argsort()[::-1]

# Output the results
print("[Query] LangChain Please tell me about.\n====================================")
for i, idx in enumerate(sorted_idx):
    print(f"[{i}] Similarity: {similarity[idx]:.3f} | {texts[idx]}")
    print()
```

Copy

```
[Query] Please tell me about LangChain. 
==================================== 
[0] Similarity: 399.644 | LangChain simplifies the process of building applications with ultra-large language models. 

[1] Similarity: 356.518 | The Langchain Korean tutorial is based on LangChain's official documents, cookbooks and various practical examples to make it easier and more effective for users to utilize LangChain.  

[2] Similarity: 322.359 | LangChain simplifies the process of building applications with large language models 

[3] Similarity: 321.078 | Hi, nice to meet you. 

[4] Similarity: 224.858 | Retrieval-Augmented Generation (RAG) is an effective technique for improving AI responses. 
```
