---
title: Voyage AI
---

>[Voyage AI](https://www.voyageai.com/)는 최첨단 embedding/vectorization 모델을 제공합니다.

Voyage AI Embedding class를 로드해봅시다. (`pip install langchain-voyageai`로 LangChain partner package를 설치하세요)

```python
from langchain_voyageai import VoyageAIEmbeddings
Voyage AI는 API key를 사용하여 사용량을 모니터링하고 권한을 관리합니다. key를 얻으려면 홈페이지에서 계정을 생성하세요. 그런 다음 API key로 VoyageEmbeddings model을 생성합니다. 다음 model 중 하나를 사용할 수 있습니다: (출처):
  • voyage-3-large
  • voyage-3
  • voyage-3-lite
  • voyage-large-2
  • voyage-code-2
  • voyage-2
  • voyage-law-2
  • voyage-large-2-instruct
  • voyage-finance-2
  • voyage-multilingual-2
embeddings = VoyageAIEmbeddings(
    voyage_api_key="[ Your Voyage API key ]", model="voyage-law-2"
)
문서를 준비하고 embed_documents를 사용하여 embedding을 얻습니다.
documents = [
    "Caching embeddings enables the storage or temporary caching of embeddings, eliminating the necessity to recompute them each time.",
    "An LLMChain is a chain that composes basic LLM functionality. It consists of a PromptTemplate and a language model (either an LLM or chat model). It formats the prompt template using the input key values provided (and also memory key values, if available), passes the formatted string to LLM and returns the LLM output.",
    "A Runnable represents a generic unit of work that can be invoked, batched, streamed, and/or transformed.",
]
documents_embds = embeddings.embed_documents(documents)
documents_embds[0][:5]
[0.0562174916267395,
 0.018221192061901093,
 0.0025736060924828053,
 -0.009720131754875183,
 0.04108370840549469]
마찬가지로 embed_query를 사용하여 query를 embedding합니다.
query = "What's an LLMChain?"
query_embd = embeddings.embed_query(query)
query_embd[:5]
[-0.0052348352037370205,
 -0.040072452276945114,
 0.0033957737032324076,
 0.01763271726667881,
 -0.019235141575336456]

미니멀리스트 검색 시스템

embedding의 주요 특징은 두 embedding 간의 cosine similarity가 해당 원본 passage의 의미적 연관성을 포착한다는 것입니다. 이를 통해 embedding을 사용하여 semantic retrieval / search를 수행할 수 있습니다. cosine similarity를 기반으로 문서 embedding에서 가장 가까운 몇 개의 embedding을 찾고, LangChain의 KNNRetriever class를 사용하여 해당 문서를 검색할 수 있습니다.
from langchain_community.retrievers import KNNRetriever

retriever = KNNRetriever.from_texts(documents, embeddings)

# retrieve the most relevant documents
result = retriever.invoke(query)
top1_retrieved_doc = result[0].page_content  # return the top1 retrieved result

print(top1_retrieved_doc)
An LLMChain is a chain that composes basic LLM functionality. It consists of a PromptTemplate and a language model (either an LLM or chat model). It formats the prompt template using the input key values provided (and also memory key values, if available), passes the formatted string to LLM and returns the LLM output.

---

<Callout icon="pen-to-square" iconType="regular">
    [Edit the source of this page on GitHub.](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/text_embedding/voyageai.mdx)
</Callout>
<Tip icon="terminal" iconType="regular">
    [Connect these docs programmatically](/use-these-docs) to Claude, VSCode, and more via MCP for    real-time answers.
</Tip>
I