Class GPTEmbeddingServiceImpl
- java.lang.Object
-
- com.composum.ai.backend.base.service.chat.impl.GPTEmbeddingServiceImpl
-
- All Implemented Interfaces:
GPTEmbeddingService
public class GPTEmbeddingServiceImpl extends Object implements GPTEmbeddingService
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.composum.ai.backend.base.service.chat.GPTEmbeddingService
GPTEmbeddingService.EmbeddingsCache
-
-
Field Summary
Fields Modifier and Type Field Description protected GPTChatCompletionService
chatCompletionService
-
Constructor Summary
Constructors Constructor Description GPTEmbeddingServiceImpl()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected double
cosineSimilarity(float[] a, float[] b)
protected static float[]
decodeFloatArray(String encodedString)
protected static String
encodeFloatArray(float[] floatArray)
List<String>
findMostRelated(String query, List<String> comparedStrings, int limit, GPTConfiguration configuration, GPTEmbeddingService.EmbeddingsCache thecache)
Determines the at most limit to query semantically closest of the comparedStrings according to the embedding service.List<float[]>
getEmbeddings(List<String> texts, GPTConfiguration configuration, GPTEmbeddingService.EmbeddingsCache cache)
Get embeddings for the given texts.
-
-
-
Field Detail
-
chatCompletionService
protected GPTChatCompletionService chatCompletionService
-
-
Method Detail
-
getEmbeddings
public List<float[]> getEmbeddings(List<String> texts, @Nullable GPTConfiguration configuration, @Nullable GPTEmbeddingService.EmbeddingsCache cache) throws GPTException
Description copied from interface:GPTEmbeddingService
Get embeddings for the given texts.- Specified by:
getEmbeddings
in interfaceGPTEmbeddingService
- Parameters:
texts
- the texts to get embeddings forconfiguration
- the configuration to use- Returns:
- the embeddings for the given texts
- Throws:
GPTException
- if an error occurs
-
findMostRelated
public List<String> findMostRelated(String query, List<String> comparedStrings, int limit, @Nullable GPTConfiguration configuration, @Nullable GPTEmbeddingService.EmbeddingsCache thecache) throws GPTException
Description copied from interface:GPTEmbeddingService
Determines the at most limit to query semantically closest of the comparedStrings according to the embedding service.- Specified by:
findMostRelated
in interfaceGPTEmbeddingService
- Throws:
GPTException
-
cosineSimilarity
protected double cosineSimilarity(float[] a, float[] b)
-
encodeFloatArray
protected static String encodeFloatArray(float[] floatArray)
-
decodeFloatArray
protected static float[] decodeFloatArray(String encodedString)
-
-