Skip to content

Commit

Permalink
additional cells and drop old doc
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul committed Aug 2, 2024
1 parent c95031b commit 660960a
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 77 deletions.
114 changes: 114 additions & 0 deletions docs/core_docs/docs/integrations/text_embedding/openai.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@
"});"
]
},
{
"cell_type": "markdown",
"id": "fb4153d3",
"metadata": {},
"source": [
"If you're part of an organization, you can set `process.env.OPENAI_ORGANIZATION` to your OpenAI organization id, or pass it in as `organization` when\n",
"initializing the model."
]
},
{
"cell_type": "markdown",
"id": "77d271b6",
Expand Down Expand Up @@ -270,6 +279,111 @@
"console.log(vectors[1].slice(0, 100));"
]
},
{
"cell_type": "markdown",
"id": "2b1a3527",
"metadata": {},
"source": [
"## Specifying dimensions\n",
"\n",
"With the `text-embedding-3` class of models, you can specify the size of the embeddings you want returned. For example by default `text-embedding-3-large` returns embeddings of dimension 3072:\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "a611fe1a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3072\n"
]
}
],
"source": [
"import { OpenAIEmbeddings } from \"@langchain/openai\";\n",
"\n",
"const embeddingsDefaultDimensions = new OpenAIEmbeddings({\n",
" model: \"text-embedding-3-large\",\n",
"});\n",
"\n",
"const vectorsDefaultDimensions = await embeddingsDefaultDimensions.embedDocuments([\"some text\"]);\n",
"console.log(vectorsDefaultDimensions[0].length);"
]
},
{
"cell_type": "markdown",
"id": "08efe771",
"metadata": {},
"source": [
"But by passing in `dimensions: 1024` we can reduce the size of our embeddings to 1024:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "19667fdb",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1024\n"
]
}
],
"source": [
"import { OpenAIEmbeddings } from \"@langchain/openai\";\n",
"\n",
"const embeddings1024 = new OpenAIEmbeddings({\n",
" model: \"text-embedding-3-large\",\n",
" dimensions: 1024,\n",
"});\n",
"\n",
"const vectors1024 = await embeddings1024.embedDocuments([\"some text\"]);\n",
"console.log(vectors1024[0].length);"
]
},
{
"cell_type": "markdown",
"id": "6b84c0df",
"metadata": {},
"source": [
"## Custom URLs\n",
"\n",
"You can customize the base URL the SDK sends requests to by passing a `configuration` parameter like this:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3bfa20a6",
"metadata": {},
"outputs": [],
"source": [
"import { OpenAIEmbeddings } from \"@langchain/openai\";\n",
"\n",
"const model = new OpenAIEmbeddings({\n",
" configuration: {\n",
" baseURL: \"https://your_custom_url.com\",\n",
" },\n",
"});"
]
},
{
"cell_type": "markdown",
"id": "ac3cac9b",
"metadata": {},
"source": [
"You can also pass other `ClientOptions` parameters accepted by the official SDK.\n",
"\n",
"If you are hosting on Azure OpenAI, see the [dedicated page instead](/docs/integrations/text_embedding/azure_openai)."
]
},
{
"cell_type": "markdown",
"id": "8938e581",
Expand Down
77 changes: 0 additions & 77 deletions docs/core_docs/docs/integrations/text_embedding/openai.mdx

This file was deleted.

0 comments on commit 660960a

Please sign in to comment.