import os# Set API keyembaas_api_key = "YOUR_API_KEY"# or set environment variableos.environ["EMBAAS_API_KEY"] = "YOUR_API_KEY"
复制
向 AI 提问
from langchain_community.embeddings import EmbaasEmbeddings
复制
向 AI 提问
embeddings = EmbaasEmbeddings()
复制
向 AI 提问
# Create embeddings for a single documentdoc_text = "This is a test document."doc_text_embedding = embeddings.embed_query(doc_text)
复制
向 AI 提问
# Print created embeddingprint(doc_text_embedding)
复制
向 AI 提问
# Create embeddings for multiple documentsdoc_texts = ["This is a test document.", "This is another test document."]doc_texts_embeddings = embeddings.embed_documents(doc_texts)
复制
向 AI 提问
# Print created embeddingsfor i, doc_text_embedding in enumerate(doc_texts_embeddings): print(f"Embedding for document {i + 1}: {doc_text_embedding}")
复制
向 AI 提问
# Using a different model and/or custom instructionembeddings = EmbaasEmbeddings( model="instructor-large", instruction="Represent the Wikipedia document for retrieval",)