Skip to content

Commit cf58034

Browse files
committed
test: add comprehensive vectorizer provider tests
- Add VectorizerProviderIntegrationTest with 27+ tests - Test all 9 providers: OpenAI, Azure OpenAI, Cohere, HuggingFace, Mistral AI, Vertex AI, Voyage AI, AWS Bedrock, Custom - Tests include single/batch embedding, caching, error handling - Use reflection for optional provider dependencies - Tests skip gracefully when API keys not set docs: enhance vectorizer documentation - Add complete examples for all 9 LangChain4J providers - Add Maven dependencies for each provider - Add caching examples with EmbeddingsCache - Add custom vectorizer implementation guide - Add provider comparison table - Fix embedMany -> embedBatch method calls - Add preprocessing examples All providers tested and documented: ✅ OpenAI (text-embedding-3-small, 1536 dims) ✅ Azure OpenAI (text-embedding-ada-002, 1536 dims) ✅ Cohere (embed-english-v3.0, 1024 dims) ✅ HuggingFace Remote API (all-MiniLM-L6-v2, 384 dims) ✅ Mistral AI (mistral-embed, 1024 dims) ✅ Vertex AI (textembedding-gecko@003, 768 dims) ✅ Voyage AI (voyage-large-2, 1536 dims) ✅ AWS Bedrock (amazon.titan-embed-text-v2:0, 1024 dims) ✅ Custom vectorizers (extend BaseVectorizer)
1 parent 2204170 commit cf58034

37 files changed

+3531
-129
lines changed

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@ build/
4646
compile_debug.log
4747
docs/.cache/*
4848
reports/*
49+
### Security - API Keys and Secrets ###
50+
# Never commit API keys, tokens, or credentials
51+
*.env
52+
.env
53+
.env.*
54+
!.env.example
55+
config.properties
56+
secrets.properties
57+
application-local.properties
58+
application-secrets.yml
59+
credentials.json
60+
api-keys.txt
61+
62+
# Notebook environment files
4963
notebooks/.env
5064

5165
### JupyterNotebooks ###

core/src/main/java/com/redis/vl/exceptions/RedisVLException.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,21 @@ public class RedisVLException extends RuntimeException {
55

66
private static final long serialVersionUID = 1L;
77

8+
/**
9+
* Constructs a new RedisVLException with the specified detail message.
10+
*
11+
* @param message the detail message
12+
*/
813
public RedisVLException(String message) {
914
super(message);
1015
}
1116

17+
/**
18+
* Constructs a new RedisVLException with the specified detail message and cause.
19+
*
20+
* @param message the detail message
21+
* @param cause the cause of the exception
22+
*/
1223
public RedisVLException(String message, Throwable cause) {
1324
super(message, cause);
1425
}

core/src/main/java/com/redis/vl/extensions/ExtensionConstants.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,68 @@
44
public final class ExtensionConstants {
55

66
// BaseMessageHistory
7+
/** Field name for message entry ID. */
78
public static final String ID_FIELD_NAME = "entry_id";
9+
10+
/** Field name for message role (e.g., user, assistant, system). */
811
public static final String ROLE_FIELD_NAME = "role";
12+
13+
/** Field name for message content. */
914
public static final String CONTENT_FIELD_NAME = "content";
15+
16+
/** Field name for tool call ID. */
1017
public static final String TOOL_FIELD_NAME = "tool_call_id";
18+
19+
/** Field name for message timestamp. */
1120
public static final String TIMESTAMP_FIELD_NAME = "timestamp";
21+
22+
/** Field name for session tag. */
1223
public static final String SESSION_FIELD_NAME = "session_tag";
1324

1425
// SemanticMessageHistory
26+
/** Field name for message vector field in semantic message history. */
1527
public static final String MESSAGE_VECTOR_FIELD_NAME = "vector_field";
1628

1729
// SemanticCache
30+
/** Field name for Redis key in semantic cache. */
1831
public static final String REDIS_KEY_FIELD_NAME = "key";
32+
33+
/** Field name for cache entry ID. */
1934
public static final String ENTRY_ID_FIELD_NAME = "entry_id";
35+
36+
/** Field name for prompt text in cache. */
2037
public static final String PROMPT_FIELD_NAME = "prompt";
38+
39+
/** Field name for response text in cache. */
2140
public static final String RESPONSE_FIELD_NAME = "response";
41+
42+
/** Field name for prompt vector in cache. */
2243
public static final String CACHE_VECTOR_FIELD_NAME = "prompt_vector";
44+
45+
/** Field name for cache insertion timestamp. */
2346
public static final String INSERTED_AT_FIELD_NAME = "inserted_at";
47+
48+
/** Field name for cache update timestamp. */
2449
public static final String UPDATED_AT_FIELD_NAME = "updated_at";
25-
public static final String METADATA_FIELD_NAME = "metadata"; // also used in MessageHistory
50+
51+
/** Field name for metadata (used in both MessageHistory and SemanticCache). */
52+
public static final String METADATA_FIELD_NAME = "metadata";
2653

2754
// EmbeddingsCache
55+
/** Field name for text in embeddings cache. */
2856
public static final String TEXT_FIELD_NAME = "text";
57+
58+
/** Field name for model name in embeddings cache. */
2959
public static final String MODEL_NAME_FIELD_NAME = "model_name";
60+
61+
/** Field name for embedding vector. */
3062
public static final String EMBEDDING_FIELD_NAME = "embedding";
63+
64+
/** Field name for embedding dimensions. */
3165
public static final String DIMENSIONS_FIELD_NAME = "dimensions";
3266

3367
// SemanticRouter
68+
/** Field name for route vector in semantic router. */
3469
public static final String ROUTE_VECTOR_FIELD_NAME = "vector";
3570

3671
private ExtensionConstants() {

core/src/main/java/com/redis/vl/extensions/cache/BaseCache.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@
1010
/** Abstract base class for all cache implementations. */
1111
public abstract class BaseCache {
1212

13+
/** The name of the cache. */
1314
protected final String name;
15+
16+
/** The Redis key prefix for this cache. */
1417
protected final String prefix;
18+
19+
/** Default time-to-live in seconds for cache entries. */
1520
protected Integer ttl;
21+
22+
/** The Redis client connection. */
1623
protected UnifiedJedis redisClient;
1724

1825
/**
@@ -36,7 +43,12 @@ protected BaseCache(String name, UnifiedJedis redisClient, Integer ttl) {
3643
this.ttl = ttl;
3744
}
3845

39-
/** Creates a new BaseCache instance without TTL. */
46+
/**
47+
* Creates a new BaseCache instance without TTL.
48+
*
49+
* @param name The name of the cache
50+
* @param redisClient The Redis client connection
51+
*/
4052
protected BaseCache(String name, UnifiedJedis redisClient) {
4153
this(name, redisClient, null);
4254
}
@@ -151,7 +163,13 @@ public void disconnect() {
151163
}
152164
}
153165

154-
/** Helper method to set a value with optional TTL. */
166+
/**
167+
* Helper method to set a value with optional TTL.
168+
*
169+
* @param key The cache key
170+
* @param value The value to store
171+
* @param ttl Time-to-live in seconds (null uses default TTL)
172+
*/
155173
protected void setWithTtl(String key, String value, Integer ttl) {
156174
SetParams params = new SetParams();
157175
Integer effectiveTtl = ttl != null ? ttl : this.ttl;
@@ -161,7 +179,13 @@ protected void setWithTtl(String key, String value, Integer ttl) {
161179
redisClient.set(key, value, params);
162180
}
163181

164-
/** Helper method to set a byte array value with optional TTL. */
182+
/**
183+
* Helper method to set a byte array value with optional TTL.
184+
*
185+
* @param key The cache key as byte array
186+
* @param value The value as byte array
187+
* @param ttl Time-to-live in seconds (null uses default TTL)
188+
*/
165189
protected void setWithTtl(byte[] key, byte[] value, Integer ttl) {
166190
if (ttl != null || this.ttl != null) {
167191
Integer effectiveTtl = ttl != null ? ttl : this.ttl;

core/src/main/java/com/redis/vl/extensions/cache/EmbeddingsCache.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ public EmbeddingsCache(String name, UnifiedJedis redisClient, Integer ttl) {
3333
super(name, redisClient, ttl);
3434
}
3535

36-
/** Creates a new EmbeddingsCache instance without TTL. */
36+
/**
37+
* Creates a new EmbeddingsCache instance without TTL.
38+
*
39+
* @param name The name of the cache
40+
* @param redisClient The Redis client connection
41+
*/
3742
public EmbeddingsCache(String name, UnifiedJedis redisClient) {
3843
this(name, redisClient, null);
3944
}

core/src/main/java/com/redis/vl/extensions/cache/SemanticCache.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,31 +497,71 @@ public static class Builder {
497497
private float distanceThreshold = 0.2f;
498498
private Integer ttl;
499499

500+
/** Create a new Builder instance */
501+
public Builder() {
502+
// Default constructor
503+
}
504+
505+
/**
506+
* Set the cache name
507+
*
508+
* @param name Cache name
509+
* @return This builder
510+
*/
500511
public Builder name(String name) {
501512
this.name = name;
502513
return this;
503514
}
504515

516+
/**
517+
* Set the Redis client
518+
*
519+
* @param redisClient UnifiedJedis client
520+
* @return This builder
521+
*/
505522
public Builder redisClient(UnifiedJedis redisClient) {
506523
this.redisClient = redisClient;
507524
return this;
508525
}
509526

527+
/**
528+
* Set the vectorizer
529+
*
530+
* @param vectorizer Vectorizer to use for embedding prompts
531+
* @return This builder
532+
*/
510533
public Builder vectorizer(BaseVectorizer vectorizer) {
511534
this.vectorizer = vectorizer;
512535
return this;
513536
}
514537

538+
/**
539+
* Set the distance threshold for semantic similarity
540+
*
541+
* @param threshold Distance threshold (default: 0.2)
542+
* @return This builder
543+
*/
515544
public Builder distanceThreshold(float threshold) {
516545
this.distanceThreshold = threshold;
517546
return this;
518547
}
519548

549+
/**
550+
* Set the TTL for cache entries
551+
*
552+
* @param ttl Time-to-live in seconds
553+
* @return This builder
554+
*/
520555
public Builder ttl(Integer ttl) {
521556
this.ttl = ttl;
522557
return this;
523558
}
524559

560+
/**
561+
* Build the SemanticCache
562+
*
563+
* @return SemanticCache instance
564+
*/
525565
public SemanticCache build() {
526566
if (name == null || name.isEmpty()) {
527567
throw new IllegalArgumentException("Cache name is required");

0 commit comments

Comments
 (0)