diff --git a/docs/content/modules/ROOT/pages/hybrid-queries.adoc b/docs/content/modules/ROOT/pages/hybrid-queries.adoc index 9e053ac..b073552 100644 --- a/docs/content/modules/ROOT/pages/hybrid-queries.adoc +++ b/docs/content/modules/ROOT/pages/hybrid-queries.adoc @@ -523,6 +523,65 @@ Filter multiFilter = Filter.and( ); ---- +== Multi-Vector Queries + +When your documents have multiple vector fields (e.g. text embeddings and image embeddings), use `MultiVectorQuery` to search across all of them simultaneously: + +[source,java] +---- +import com.redis.vl.query.MultiVectorQuery; +import com.redis.vl.query.Vector; + +Vector textVec = Vector.builder() + .vector(textEmbedding) + .fieldName("text_embedding") + .weight(0.7) + .build(); + +Vector imageVec = Vector.builder() + .vector(imageEmbedding) + .fieldName("image_embedding") + .weight(0.3) + .build(); + +MultiVectorQuery query = MultiVectorQuery.builder() + .vectors(textVec, imageVec) + .returnFields("title", "category") + .numResults(10) + .build(); + +List> results = index.query(query); +---- + +Results are scored using a weighted combination of the individual vector similarities. + +=== Per-Vector Distance Thresholds + +Each vector can have its own `maxDistance` to control how similar results must be for that particular field. Values range from 0.0 (exact match only) to 2.0 (include everything): + +[source,java] +---- +// Tight threshold on text, loose on image +Vector textVec = Vector.builder() + .vector(textEmbedding) + .fieldName("text_embedding") + .maxDistance(0.3) // only very similar text + .build(); + +Vector imageVec = Vector.builder() + .vector(imageEmbedding) + .fieldName("image_embedding") + .maxDistance(1.5) // broader image matches + .build(); + +MultiVectorQuery query = MultiVectorQuery.builder() + .vectors(textVec, imageVec) + .numResults(10) + .build(); +---- + +When `maxDistance` is not set, it defaults to 2.0 (no distance filtering). + == Tips for Effective Hybrid Queries . *Use Pre-Filtering* - More efficient than post-filtering diff --git a/docs/content/modules/ROOT/pages/message-history.adoc b/docs/content/modules/ROOT/pages/message-history.adoc index 274160b..c4626d6 100644 --- a/docs/content/modules/ROOT/pages/message-history.adoc +++ b/docs/content/modules/ROOT/pages/message-history.adoc @@ -18,7 +18,9 @@ MessageHistory chatHistory = new MessageHistory("student tutor", jedis); ---- To align with common LLM APIs, Redis stores messages with `role` and `content` fields. -The supported roles are "system", "user" and "llm". +The supported roles are defined by the `ChatRole` enum: `user`, `assistant`, `system`, and `tool`. + +NOTE: The role `llm` is accepted for backward compatibility but is deprecated. Use `assistant` instead. You can store messages one at a time or all at once. @@ -82,6 +84,19 @@ Output: {role=llm, content=England is larger in land area than Portugal by about 15000 square miles.} ---- +== Counting messages + +You can count the number of messages stored for the current session, or for a specific session tag: + +[source,java] +---- +// Count messages in the default session +long messageCount = chatHistory.count(); + +// Count messages in a specific session +long sessionCount = chatHistory.count("student two"); +---- + == Managing multiple users and conversations For applications that need to handle multiple conversations concurrently, Redis supports tagging messages to keep conversations separated.