embaas title

This commit is contained in:
Harrison Chase 2023-06-12 08:00:14 -07:00
parent 7a5e36f3f5
commit 681ba6d520

View File

@ -2,142 +2,127 @@
"cells": [ "cells": [
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {},
"source": [ "source": [
"# Embaas\n",
"\n",
"[embaas](https://embaas.io) is a fully managed NLP API service that offers features like embedding generation, document text extraction, document to embeddings and more. You can choose a [variety of pre-trained models](https://embaas.io/docs/models/embeddings).\n", "[embaas](https://embaas.io) is a fully managed NLP API service that offers features like embedding generation, document text extraction, document to embeddings and more. You can choose a [variety of pre-trained models](https://embaas.io/docs/models/embeddings).\n",
"\n", "\n",
"In this tutorial, we will show you how to use the embaas Embeddings API to generate embeddings for a given text.\n", "In this tutorial, we will show you how to use the embaas Embeddings API to generate embeddings for a given text.\n",
"\n", "\n",
"### Prerequisites\n", "### Prerequisites\n",
"Create your free embaas account at [https://embaas.io/register](https://embaas.io/register) and generate an [API key](https://embaas.io/dashboard/api-keys)." "Create your free embaas account at [https://embaas.io/register](https://embaas.io/register) and generate an [API key](https://embaas.io/dashboard/api-keys)."
], ]
"metadata": {
"collapsed": false
}
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"# Set API key\n", "# Set API key\n",
"embaas_api_key = \"YOUR_API_KEY\"\n", "embaas_api_key = \"YOUR_API_KEY\"\n",
"# or set environment variable\n", "# or set environment variable\n",
"os.environ[\"EMBAAS_API_KEY\"] = \"YOUR_API_KEY\"" "os.environ[\"EMBAAS_API_KEY\"] = \"YOUR_API_KEY\""
], ]
"metadata": {
"collapsed": false
}
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"from langchain.embeddings import EmbaasEmbeddings" "from langchain.embeddings import EmbaasEmbeddings"
], ]
"metadata": {
"collapsed": false
}
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"embeddings = EmbaasEmbeddings()" "embeddings = EmbaasEmbeddings()"
], ]
"metadata": {
"collapsed": false
}
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2023-06-10T11:17:55.940265Z",
"start_time": "2023-06-10T11:17:55.938517Z"
}
},
"outputs": [], "outputs": [],
"source": [ "source": [
"# Create embeddings for a single document\n", "# Create embeddings for a single document\n",
"doc_text = \"This is a test document.\"\n", "doc_text = \"This is a test document.\"\n",
"doc_text_embedding = embeddings.embed_query(doc_text)" "doc_text_embedding = embeddings.embed_query(doc_text)"
], ]
"metadata": {
"collapsed": false,
"ExecuteTime": {
"start_time": "2023-06-10T11:17:55.938517Z",
"end_time": "2023-06-10T11:17:55.940265Z"
}
}
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"# Print created embedding\n", "# Print created embedding\n",
"print(doc_text_embedding)" "print(doc_text_embedding)"
], ]
"metadata": {
"collapsed": false
}
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": 9,
"metadata": {
"ExecuteTime": {
"end_time": "2023-06-10T11:19:25.237161Z",
"start_time": "2023-06-10T11:19:25.235320Z"
}
},
"outputs": [], "outputs": [],
"source": [ "source": [
"# Create embeddings for multiple documents\n", "# Create embeddings for multiple documents\n",
"doc_texts = [\"This is a test document.\", \"This is another test document.\"]\n", "doc_texts = [\"This is a test document.\", \"This is another test document.\"]\n",
"doc_texts_embeddings = embeddings.embed_documents(doc_texts)" "doc_texts_embeddings = embeddings.embed_documents(doc_texts)"
], ]
"metadata": {
"collapsed": false,
"ExecuteTime": {
"start_time": "2023-06-10T11:19:25.235320Z",
"end_time": "2023-06-10T11:19:25.237161Z"
}
}
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"# Print created embeddings\n", "# Print created embeddings\n",
"for i, doc_text_embedding in enumerate(doc_texts_embeddings):\n", "for i, doc_text_embedding in enumerate(doc_texts_embeddings):\n",
" print(f\"Embedding for document {i + 1}: {doc_text_embedding}\")" " print(f\"Embedding for document {i + 1}: {doc_text_embedding}\")"
], ]
"metadata": {
"collapsed": false
}
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": 11,
"metadata": {
"ExecuteTime": {
"end_time": "2023-06-10T11:22:26.139769Z",
"start_time": "2023-06-10T11:22:26.138357Z"
}
},
"outputs": [], "outputs": [],
"source": [ "source": [
"# Using a different model and/or custom instruction\n", "# Using a different model and/or custom instruction\n",
"embeddings = EmbaasEmbeddings(model=\"instructor-large\", instruction=\"Represent the Wikipedia document for retrieval\")" "embeddings = EmbaasEmbeddings(model=\"instructor-large\", instruction=\"Represent the Wikipedia document for retrieval\")"
], ]
"metadata": {
"collapsed": false,
"ExecuteTime": {
"start_time": "2023-06-10T11:22:26.138357Z",
"end_time": "2023-06-10T11:22:26.139769Z"
}
}
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {},
"source": [ "source": [
"For more detailed information about the embaas Embeddings API, please refer to [the official embaas API documentation](https://embaas.io/api-reference)." "For more detailed information about the embaas Embeddings API, please refer to [the official embaas API documentation](https://embaas.io/api-reference)."
], ]
"metadata": {
"collapsed": false
}
} }
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Python 3", "display_name": "Python 3 (ipykernel)",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@ -155,5 +140,5 @@
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }