# 04. UpstageEmbeddings Copy

```
# API KEY  configuration file for managing environment variables
from dotenv import load_dotenv

# API KEY load information
load_dotenv()
```

Copy

```
True
```

### Upstage <a href="#upstage" id="upstage"></a>

Upstage is a domestic startup specialized in artificial intelligence (AI) technology, especially large language models (LLM) and document AI.

**API key issuance**

* API key issuance [Upstage API Console ](https://console.upstage.ai/api-keys)Available in.

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, cookbook And it is structured to help users utilize LangChain more easily and effectively based on 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://developers.upstage.ai/docs/apis/embeddings>

**Model information**

Model

Release date

Context Length

Description

solar-embedding-1-large-query

2024-05-10

4000

Solar-base Query Embedding model with 4k context limitation. This model is optimized for embedding user questions in information exploration tasks such as search and realignment.

solar-embedding-1-large-passage

2024-05-10

4000

Solar-base Passage Embedding model with 4k context limitation. This model is optimized for embedding documents or text to search for.

Copy

```
from langchain_upstage import UpstageEmbeddings

# Query-only embedding model
query_embeddings = UpstageEmbeddings(model="solar-embedding-1-large-query")

# Sentence-only embedding model
passage_embeddings = UpstageEmbeddings(model="solar-embedding-1-large-passage")
```

`Query` Embed.

Copy

```
# Query embedding
embedded_query = query_embeddings.embed_query("LangChain Please tell me in detail.")
# Embedding dimension output
len(embedded_query)
```

Copy

```
4096 
```

Embed documents.

Copy

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

Similarity outputs the calculation result.

Copy

```
import numpy as np

# Question (embedded_query): Please tell me about LangChain.
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: 0.487 | LangChain simplifies the process of building applications with ultra-large language models. 

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

[2] Similarity: 0.432 | The Langchain Korean tutorial is based on LangChain's official documentation, cookbooks, and various practical examples to make it easier and more effective for users to use LangChain.  

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

[4] Similarity: 0.151 | Hi, Nice to meet you. 

```
