Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
OurBuilding Ambient Agents with LangGraph course is now available on LangChain Academy!
Open In ColabOpen on GitHub

DeepInfra

DeepInfra is a serverless inference as a service that provides access to avariety of LLMs andembeddings models. This notebook goes over how to use LangChain with DeepInfra for text embeddings.

# sign up for an account: https://deepinfra.com/login?utm_source=langchain

from getpassimport getpass

DEEPINFRA_API_TOKEN= getpass()
 ········
import os

os.environ["DEEPINFRA_API_TOKEN"]= DEEPINFRA_API_TOKEN
from langchain_community.embeddingsimport DeepInfraEmbeddings
API Reference:DeepInfraEmbeddings
embeddings= DeepInfraEmbeddings(
model_id="sentence-transformers/clip-ViT-B-32",
query_instruction="",
embed_instruction="",
)
docs=["Dog is not a cat","Beta is the second letter of Greek alphabet"]
document_result= embeddings.embed_documents(docs)
query="What is the first letter of Greek alphabet"
query_result= embeddings.embed_query(query)
import numpyas np

query_numpy= np.array(query_result)
for doc_res, docinzip(document_result, docs):
document_numpy= np.array(doc_res)
similarity= np.dot(query_numpy, document_numpy)/(
np.linalg.norm(query_numpy)* np.linalg.norm(document_numpy)
)
print(f'Cosine similarity between "{doc}" and query:{similarity}')
Cosine similarity between "Dog is not a cat" and query: 0.7489097144129355
Cosine similarity between "Beta is the second letter of Greek alphabet" and query: 0.9519380640702013

Related


[8]ページ先頭

©2009-2025 Movatter.jp