跳到主要内容
让我们加载 LLMRails Embeddings 类。 要使用 LLMRails 嵌入,您需要通过参数传入 API 密钥,或将其设置为环境变量 LLM_RAILS_API_KEY。要获取 API 密钥,您需要在 console.llmrails.com/signup 注册,然后前往 console.llmrails.com/api-keys 并在平台上创建密钥后复制密钥。
from langchain_community.embeddings import LLMRailsEmbeddings
embeddings = LLMRailsEmbeddings(model="embedding-english-v1")  # or embedding-multi-v1
text = "This is a test document."
要生成嵌入,您可以查询单个文本,也可以查询文本列表。
query_result = embeddings.embed_query(text)
query_result[:5]
[-0.09996652603149414,
 0.015568195842206478,
 0.17670190334320068,
 0.16521021723747253,
 0.21193109452724457]
doc_result = embeddings.embed_documents([text])
doc_result[0][:5]
[-0.04242777079343796,
 0.016536075621843338,
 0.10052520781755447,
 0.18272875249385834,
 0.2079043835401535]

以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.