mirror of
https://github.com/hwchase17/langchain.git
synced 2025-10-02 02:38:36 +00:00
More than 300 files - will fail check_diff. Will merge after Vercel deploy succeeds Still occurrences that need changing - will update more later
135 lines
2.8 KiB
Plaintext
135 lines
2.8 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "raw",
|
|
"id": "afaf8039",
|
|
"metadata": {},
|
|
"source": [
|
|
"---\n",
|
|
"sidebar_label: Together AI\n",
|
|
"---"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "e49f1e0d",
|
|
"metadata": {},
|
|
"source": [
|
|
"# TogetherEmbeddings\n",
|
|
"\n",
|
|
"This notebook covers how to get started with open source embedding models hosted in the Together AI API.\n",
|
|
"\n",
|
|
"## Installation"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "4c3bef91",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# install package\n",
|
|
"%pip install --upgrade --quiet langchain-together"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "2b4f3e15",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Environment Setup\n",
|
|
"\n",
|
|
"Make sure to set the following environment variables:\n",
|
|
"\n",
|
|
"- `TOGETHER_API_KEY`\n",
|
|
"\n",
|
|
"## Usage\n",
|
|
"\n",
|
|
"First, select a supported model from [this list](https://docs.together.ai/docs/embedding-models). In the following example, we will use `togethercomputer/m2-bert-80M-8k-retrieval`."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "62e0dbc3",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"from langchain_together.embeddings import TogetherEmbeddings\n",
|
|
"\n",
|
|
"embeddings = TogetherEmbeddings(model=\"togethercomputer/m2-bert-80M-8k-retrieval\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "12fcfb4b",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"embeddings.embed_query(\"My query to look up\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "1f2e6104",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"embeddings.embed_documents(\n",
|
|
" [\"This is a content of the document\", \"This is another document\"]\n",
|
|
")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "46739f68",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# async embed query\n",
|
|
"await embeddings.aembed_query(\"My query to look up\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "e48632ea",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# async embed documents\n",
|
|
"await embeddings.aembed_documents(\n",
|
|
" [\"This is a content of the document\", \"This is another document\"]\n",
|
|
")"
|
|
]
|
|
}
|
|
],
|
|
"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.10.5"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|