Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[doc] Add docs for ZhipuAI Embeddings #25214

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 163 additions & 0 deletions docs/docs/integrations/text_embedding/zhipuai.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
{
"cells": [
{
"cell_type": "raw",
"metadata": {},
"source": [
"# ZHIPU AI\n",
"\n",
"This notebook shows how to use Langchain with [ZhipuAI](https://open.bigmodel.cn/console/overview) embeddings models.\n",
"\n",
"To use, you should have the `zhipuai` python package installed."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"%pip install --upgrade --quiet zhipuai"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"After installation,sign in to [ZHIPU AI](https://open.bigmodel.cn/usercenter/apikeys) for the an API Key to access our models.\n",
"\n",
"import os\n",
"\n",
"os.environ[\"ZHIPUAI_API_KEY\"] = \"zhipuai_api_key\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Then, you can use `ZhipuAIEmbeddings` API for text embedding."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"from langchain_community.embeddings import ZhipuAIEmbeddings"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"embeddings = ZhipuAIEmbeddings(model=\"embedding-3\")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"query = \"This is a test document.\""
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"query_embedding = embeddings.embed_query(query)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"doc_embedding = embeddings.embed_documents([query])"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[-0.029220581, 0.0034008026, -0.020065308, 0.001244545, -0.007461548]"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"query_embedding[:5]"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[-0.029220581, 0.0034008026, -0.020065308, 0.001244545, -0.007461548]"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"doc_embedding[0][:5]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading