Class OpenAIEmbeddings

java.lang.Object
com.hw.langchain.embeddings.openai.OpenAIEmbeddings
All Implemented Interfaces:
Embeddings

public class OpenAIEmbeddings extends Object implements Embeddings
Wrapper around OpenAI embedding models.

To use, you should have the environment variable OPENAI_API_KEY set with your API key or pass it as a named parameter to the constructor.

Author:
HamaWhite
  • Field Details

    • openaiOrganization

      protected String openaiOrganization
    • requestTimeout

      protected long requestTimeout
      Timeout for requests to OpenAI completion API. Default is 16 seconds.
  • Constructor Details

    • OpenAIEmbeddings

      public OpenAIEmbeddings()
  • Method Details

    • init

      public OpenAIEmbeddings init()
      Validate parameters and init client
    • embeddingFunc

      public List<Float> embeddingFunc(String text)
      Call out to OpenAI's embedding endpoint.
    • embedDocuments

      public List<List<Float>> embedDocuments(List<String> texts)
      Call out to OpenAI's embedding endpoint for embedding search docs.
      Specified by:
      embedDocuments in interface Embeddings
      Parameters:
      texts - The list of texts to embed.
      Returns:
      List of embeddings, one for each text.
    • embedQuery

      public List<Float> embedQuery(String text)
      Call out to OpenAI's embedding endpoint for embedding query text.
      Specified by:
      embedQuery in interface Embeddings
      Parameters:
      text - The text to embed.
      Returns:
      Embedding for the text.
    • embedWithRetry

      public EmbeddingResp embedWithRetry(List<?> input)