Working with Embeddings
Learn how to work with vector embeddings in Polyglot.
The Embeddings Class
Polyglot provides the Embeddings
class as the primary interface for generating and working with vector embeddings.
Creating an Embeddings Instance
Key Methods
The Embeddings
class provides several important methods:
create()
: Generates embeddings for input textwithConnection()
: Specifies which connection to usewithConfig()
: Sets a custom configurationwithHttpClient()
: Specifies a custom HTTP clientwithModel()
: Overrides the default modelfindSimilar()
: Finds documents similar to a query
Generating Embeddings
The core functionality of the Embeddings
class is to transform text into vector representations.
Basic Embedding Generation
Embedding Multiple Texts
You can generate embeddings for multiple texts in a single request, which is more efficient than making separate requests:
Accessing Embedding Results
The create()
method returns an EmbeddingsResponse
object with several useful methods:
Working with Vector Objects
Each vector in the response is represented by a Vector
object with its own methods:
Working with Different Providers
Polyglot supports multiple embedding providers, each with their own strengths and characteristics.
Switching Between Providers
Provider-Specific Options
Different providers may support additional options for embedding generation:
Models and Dimensions
Different embedding models produce vectors of different dimensions: