Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
eyurtsev committed Aug 12, 2024
1 parent 2f3ab8f commit 1d437df
Showing 1 changed file with 64 additions and 65 deletions.
129 changes: 64 additions & 65 deletions libs/partners/openai/langchain_openai/embeddings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,87 +101,86 @@ def _process_batched_chunked_embeddings(
class OpenAIEmbeddings(BaseModel, Embeddings):
"""OpenAI embedding model integration.
Setup:
Install ``langchain_openai`` and set environment variable ``OPENAI_API_KEY``.
.. code-block:: bash
pip install -U langchain_openai
export OPENAI_API_KEY="your-api-key"
Key init args — embedding params:
model: str
Name of OpenAI model to use.
dimensions: Optional[int] = None
The number of dimensions the resulting output embeddings should have.
Only supported in `text-embedding-3` and later models.
Key init args — client params:
api_key: Optional[SecretStr] = None
OpenAI API key.
organization: Optional[str] = None
OpenAI organization ID. If not passed in will be read
from env var OPENAI_ORG_ID.
max_retries: int = 2
Maximum number of retries to make when generating.
request_timeout: Optional[Union[float, Tuple[float, float], Any]] = None
Timeout for requests to OpenAI completion API
See full list of supported init args and their descriptions in the params section.
Instantiate:
.. code-block:: python
from langchain_openai import OpenAIEmbeddings
embed = OpenAIEmbeddings(
model="text-embedding-3-large",
# With the `text-embedding-3` class
# of models, you can specify the size
# of the embeddings you want returned.
# dimensions=1024
)
Setup:
Install ``langchain_openai`` and set environment variable ``OPENAI_API_KEY``.
Embed single text:
.. code-block:: bash
.. code-block:: python
pip install -U langchain_openai
export OPENAI_API_KEY="your-api-key"
input_text = "The meaning of life is 42"
vector = embeddings.embed_query('hello')
print(vector[:3])
Key init args — embedding params:
model: str
Name of OpenAI model to use.
dimensions: Optional[int] = None
The number of dimensions the resulting output embeddings should have.
Only supported in `text-embedding-3` and later models.
.. code-block:: python
Key init args — client params:
api_key: Optional[SecretStr] = None
OpenAI API key.
organization: Optional[str] = None
OpenAI organization ID. If not passed in will be read
from env var OPENAI_ORG_ID.
max_retries: int = 2
Maximum number of retries to make when generating.
request_timeout: Optional[Union[float, Tuple[float, float], Any]] = None
Timeout for requests to OpenAI completion API
[-0.024603435769677162, -0.007543657906353474, 0.0039630369283258915]
See full list of supported init args and their descriptions in the params section.
Embed multiple texts:
Instantiate:
.. code-block:: python
.. code-block:: python
from langchain_openai import OpenAIEmbeddings
vectors = embeddings.embed_documents(['hello', 'goodbye'])
# Showing only the first 3 coordinates
print(len(vectors))
print(vectors[0][:3])
embed = OpenAIEmbeddings(
model="text-embedding-3-large"
# With the `text-embedding-3` class
# of models, you can specify the size
# of the embeddings you want returned.
# dimensions=1024
)
.. code-block:: python
Embed single text:
2
[-0.024603435769677162, -0.007543657906353474, 0.0039630369283258915]
.. code-block:: python
Async:
.. code-block:: python
input_text = "The meaning of life is 42"
vector = embeddings.embed_query("hello")
print(vector[:3])
await embed.aembed_query(input_text)
print(vector[:3])
.. code-block:: python
# multiple:
# await embed.aembed_documents(input_texts)
[-0.024603435769677162, -0.007543657906353474, 0.0039630369283258915]
.. code-block:: python
Embed multiple texts:
[-0.009100092574954033, 0.005071679595857859, -0.0029193938244134188]
"""
.. code-block:: python
vectors = embeddings.embed_documents(["hello", "goodbye"])
# Showing only the first 3 coordinates
print(len(vectors))
print(vectors[0][:3])
.. code-block:: python
2
[-0.024603435769677162, -0.007543657906353474, 0.0039630369283258915]
Async:
.. code-block:: python
await embed.aembed_query(input_text)
print(vector[:3])
# multiple:
# await embed.aembed_documents(input_texts)
.. code-block:: python
[-0.009100092574954033, 0.005071679595857859, -0.0029193938244134188]
"""

client: Any = Field(default=None, exclude=True) #: :meta private:
async_client: Any = Field(default=None, exclude=True) #: :meta private:
Expand Down

0 comments on commit 1d437df

Please sign in to comment.