OpenAIEmbeddings features and configuration options, please refer to the API reference.
Overview
Integration details
| Class | Package | Local | Py support | Downloads | Version | 
|---|---|---|---|---|---|
| OpenAIEmbeddings | @langchain/openai | ❌ | ✅ | 
Setup
To access OpenAIEmbeddings embedding models you’ll need to create an OpenAI account, get an API key, and install the@langchain/openai integration package.
Credentials
Head to platform.openai.com to sign up to OpenAI and generate an API key. Once you’ve done this set theOPENAI_API_KEY environment variable:
Installation
The LangChain OpenAIEmbeddings integration lives in the@langchain/openai package:
Instantiation
Now we can instantiate our model object and generate chat completions:process.env.OPENAI_ORGANIZATION to your OpenAI organization id, or pass it in as organization when
initializing the model.
Indexing and Retrieval
Embedding models are often used in retrieval-augmented generation (RAG) flows, both as part of indexing data as well as later retrieving it. For more detailed instructions, please see our RAG tutorials under the Learn tab. Below, see how to index and retrieve data using theembeddings object we initialized above. In this example, we will index and retrieve a sample document using the demo MemoryVectorStore.
Direct Usage
Under the hood, the vectorstore and retriever implementations are callingembeddings.embedDocument(...) and embeddings.embedQuery(...) to create embeddings for the text(s) used in fromDocuments and the retriever’s invoke operations, respectively.
You can directly call these methods to get embeddings for your own use cases.
Embed single texts
You can embed queries for search withembedQuery. This generates a vector representation specific to the query:
Embed multiple texts
You can embed multiple texts for indexing withembedDocuments. The internals used for this method may (but do not have to) differ from embedding queries:
Specifying dimensions
With thetext-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:
dimensions: 1024 we can reduce the size of our embeddings to 1024:
Custom URLs
You can customize the base URL the SDK sends requests to by passing aconfiguration parameter like this:
ClientOptions parameters accepted by the official SDK.
If you are hosting on Azure OpenAI, see the dedicated page instead.
API reference
For detailed documentation of all OpenAIEmbeddings features and configurations head to the API reference.Connect these docs programmatically to Claude, VSCode, and more via MCP for    real-time answers.