This notebook covers how to get started with embedding models provided by CLOVA Studio. For detailed documentation on ClovaXEmbeddings
features and configuration options, please refer to the API reference.
Before using embedding models provided by CLOVA Studio, you must go through the three steps below.
Set the CLOVASTUDIO_API_KEY
environment variable with your API key.
import getpass
import os
if not os.getenv("CLOVASTUDIO_API_KEY"):
os.environ["CLOVASTUDIO_API_KEY"] = getpass.getpass("Enter CLOVA Studio API Key: ")
Installation
ClovaXEmbeddings integration lives in the langchain_naver
package:
%pip install -qU langchain-naver
Instantiation
Now we can instantiate our embeddings object and embed query or document:
from langchain_naver import ClovaXEmbeddings
embeddings = ClovaXEmbeddings(
model="clir-emb-dolphin"
)
Indexing and Retrieval
Embedding models are often used in retrieval-augmented generation (RAG) flows, both as part of indexing data as well as later retrieving it. For more detailed instructions, please see our RAG tutorials.
Below, see how to index and retrieve data using the embeddings
object we initialized above. In this example, we will index and retrieve a sample document in the InMemoryVectorStore
.
from langchain_core.vectorstores import InMemoryVectorStore
text = "CLOVA Studio is an AI development tool that allows you to customize your own HyperCLOVA X models."
vectorstore = InMemoryVectorStore.from_texts(
[text],
embedding=embeddings,
)
retriever = vectorstore.as_retriever()
retrieved_documents = retriever.invoke("What is CLOVA Studio?")
retrieved_documents[0].page_content
'CLOVA Studio is an AI development tool that allows you to customize your own HyperCLOVA X models.'
Direct Usage
Under the hood, the vectorstore and retriever implementations are calling embeddings.embed_documents(...)
and embeddings.embed_query(...)
to create embeddings for the text(s) used in from_texts
and retrieval invoke
operations, respectively.
You can directly call these methods to get embeddings for your own use cases.
Embed single textsYou can embed single texts or documents with embed_query
:
single_vector = embeddings.embed_query(text)
print(str(single_vector)[:100])
[-0.094717406, -0.4077411, -0.5513184, 1.6024436, -1.3235079, -1.0720996, -0.44471845, 1.3665184, 0.
Embed multiple texts
You can embed multiple texts with embed_documents
:
text2 = "LangChain is a framework for building context-aware reasoning applications"
two_vectors = embeddings.embed_documents([text, text2])
for vector in two_vectors:
print(str(vector)[:100])
[-0.094717406, -0.4077411, -0.5513184, 1.6024436, -1.3235079, -1.0720996, -0.44471845, 1.3665184, 0.
[-0.25525448, -0.84877056, -0.6928286, 1.5867524, -1.2930486, -0.8166254, -0.17934391, 1.4236152, 0.
API Reference
For detailed documentation on ClovaXEmbeddings
features and configuration options, please refer to the API reference.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4