Replace the Embedding format from List<Double> to float[]

- Adjust all affected classes including the Document.
 - Update docs.

Related to #405
This commit is contained in:
Christian Tzolov
2024-07-03 14:42:27 +02:00
committed by Mark Pollack
parent 656fa8b4fe
commit d538e00643
67 changed files with 442 additions and 412 deletions

View File

@@ -50,14 +50,14 @@ public interface EmbeddingModel extends Model<EmbeddingRequest, EmbeddingRespons
* @param document the document to embed.
* @return the embedded vector.
*/
List<Double> embed(Document document);
float[] embed(Document document);
/**
* Embeds the given text into a vector.
* @param text the text to embed.
* @return the embedded vector.
*/
default List<Double> embed(String text) {
default float[] embed(String text) {
Assert.notNull(text, "Text must not be null");
return this.embed(List.of(text)).iterator().next();
}
@@ -67,7 +67,7 @@ public interface EmbeddingModel extends Model<EmbeddingRequest, EmbeddingRespons
* @param texts list of texts to embed.
* @return list of list of embedded vectors.
*/
default List<List<Double>> embed(List<String> texts) {
default List<float[]> embed(List<String> texts) {
Assert.notNull(texts, "Texts must not be null");
return this.call(new EmbeddingRequest(texts, EmbeddingOptions.EMPTY))
.getResults()
@@ -102,7 +102,7 @@ The embed methods offer various options for converting text into embeddings, acc
Multiple shortcut methods are provided for embedding text, including the `embed(String text)` method, which takes a single string and returns the corresponding embedding vector.
All shortcuts are implemented around the `call` method, which is the primary method for invoking the embedding model.
Typically the embedding returns a lists of doubles, representing the embeddings in a numerical vector format.
Typically the embedding returns a lists of floats, representing the embeddings in a numerical vector format.
The `embedForResponse` method provides a more comprehensive output, potentially including additional information about the embeddings.
@@ -146,8 +146,8 @@ The `Embedding` represents a single embedding vector.
[source,java]
----
public class Embedding implements ModelResult<List<Double>> {
private List<Double> embedding;
public class Embedding implements ModelResult<float[]> {
private float[] embedding;
private Integer index;
private EmbeddingResultMetadata metadata;
// other methods omitted

View File

@@ -71,7 +71,7 @@ To insert data into the vector database, encapsulate it within a `Document` obje
The `Document` class encapsulates content from a data source, such as a PDF or Word document, and includes text represented as a string.
It also contains metadata in the form of key-value pairs, including details such as the filename.
Upon insertion into the vector database, the text content is transformed into a numerical array, or a `List<Double>`, known as vector embeddings, using an embedding model. Embedding models, such as https://en.wikipedia.org/wiki/Word2vec[Word2Vec], https://en.wikipedia.org/wiki/GloVe_(machine_learning)[GLoVE], and https://en.wikipedia.org/wiki/BERT_(language_model)[BERT], or OpenAI's `text-embedding-ada-002`, are used to convert words, sentences, or paragraphs into these vector embeddings.
Upon insertion into the vector database, the text content is transformed into a numerical array, or a `float[]`, known as vector embeddings, using an embedding model. Embedding models, such as https://en.wikipedia.org/wiki/Word2vec[Word2Vec], https://en.wikipedia.org/wiki/GloVe_(machine_learning)[GLoVE], and https://en.wikipedia.org/wiki/BERT_(language_model)[BERT], or OpenAI's `text-embedding-ada-002`, are used to convert words, sentences, or paragraphs into these vector embeddings.
The vector database's role is to store and facilitate similarity searches for these embeddings. It does not generate the embeddings itself. For creating vector embeddings, the `EmbeddingModel` should be utilized.