Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions docs/content/modules/ROOT/pages/hybrid-queries.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Map<String, Object>> 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
Expand Down
17 changes: 16 additions & 1 deletion docs/content/modules/ROOT/pages/message-history.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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.
Expand Down
Loading