VoyageAI by MongoDB 使用 API 密钥来监控使用情况和管理权限。要获取您的密钥,请在我们的 主页 上创建账户。然后,使用您的 API 密钥创建 VoyageEmbeddings 模型。您可以使用以下任何模型:(来源):
voyage-4-large
voyage-4
voyage-4-lite
voyage-code-4
voyage-context-4
voyage-context-3
voyage-3.5
voyage-3.5-lite
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 获取它们的嵌入。
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.",]
from langchain_community.retrievers import KNNRetrieverretriever = KNNRetriever.from_texts(documents, embeddings)# retrieve the most relevant documentsresult = retriever.invoke(query)top1_retrieved_doc = result[0].page_content # return the top1 retrieved resultprint(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.