The Embeddings Class
Polyglot provides theEmbeddings
class as the primary interface for generating and working with vector embeddings.
Creating an Embeddings Instance
Key Methods
TheEmbeddings
class provides several important methods:
create()
: Generates embeddings for input textusing()
: Specifies which connection preset 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 theEmbeddings
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
Thecreate()
method returns an EmbeddingsResponse
object with several useful methods:
Working with Vector Objects
Each vector in the response is represented by aVector
object with its own methods: