Vector Sets in Redis on Java
Artificial intelligence and machine learning (ML) have been the most significant developments in software development since the cloud made global distributed applications a reality. Developers looking to build a recommendation engine, a semantic search tool, or any number of apps that use high-dimensional data now have extremely powerful tools at their disposal. But first, developers must learn to harness the power of the vector set.
Since version 8, Redis has established itself as the vector database of choice for developers, thanks to its unrivaled speed, low-latency performance, and its ability to combine vector search with real-time data processing.
However, for Java developers, interacting with these raw low-level Redis commands — defining schemas, creating indices manually with FT.CREATE and managing complex query syntax — can be a time-consuming bottleneck. Fortunately, Redisson bridges the gap between the complex world of vector databases and the familiar, object-oriented environment of Java.
The Power of Redis, the Familiarity of Java
As the leading Java client for Redis, Redisson simplifies vector search implementation by abstracting it into familiar, straightforward methods and classes.
Instead of wrestling with raw protocol commands or manually managing binary arrays, Redisson introduces the RVectorSet interface. This allows you to treat a vector set just like a standard Java collection — but with supercharged ML capabilities.
With Redisson, you can fully tap into the power of Redis as a vector database. Redis supports advanced vector search capabilities, including the HNSW (Hierarchical Navigable Small World) algorithm. These features allow for approximate nearest neighbor (ANN) searches, essential tools for finding similar terms in massive datasets.
Simplified Vector Search Integration
So, whether you are enhancing an eCommerce platform with visual search or building an LLM-backed tool, Redis is the data store for your app. Redisson — with its native Java integration, HNSW support, and seamless JSON attribute management — simplifies vector search integration for Java developers.
See how easy it is with this code sample:
import org.redisson.api.RVectorSet;
import org.redisson.api.RedissonClient;
import org.redisson.api.search.VectorSimilarArgs;
import org.redisson.api.search.VectorAddArgs;
import java.util.List;
public class VectorSearchExample {
public static void main(String[] args) {
RedissonClient redisson = ...
// Get access to the Vector Set
RVectorSet vectorSet = redisson.getVectorSet("document-embeddings");
// 1. Add an element with a vector and metadata attributes
// Use document ID "doc-123" and its calculated vector
vectorSet.add(VectorAddArgs.element("doc-123")
.vector(0.12, -0.34, 0.56, 0.78) // Your high-dimensional vector
.attributes("{\"category\": \"finance\", \"year\": 2024}"));
// 2. Perform a similarity search
// Find the top 10 most similar documents to a query vector
List similarDocs = vectorSet.getSimilar(
VectorSimilarArgs.vector(0.15, -0.30, 0.55, 0.80)
.count(10));
System.out.println("Found similar documents: " + similarDocs);
// You can even find similar items to an existing stored document
List relatedToDoc123 = vectorSet.getSimilar(
VectorSimilarArgs.element("doc-123").count(5));
}
}
Unlock the Potential of Redis and the Vector Set
The vector set doesn't have to complicate your Java development. With Redisson, you can unlock the full potential of Redis as a vector database while staying within the comfort of the Java ecosystem.
To bring enterprise-grade vector capabilities to your Java applications, learn more about Redisson PRO today.