Repository navigation
Description
I am using Redis.OM as storage for a GraphQL API using Hot Chocolate and I have run into problems when I started using Vector fields in my JSON objects. I used IRedisCollection like a DbSet and return IQueryable objects to Hot Chocolate to serve queries. In the sample below everything works fine until I add the Vec field. At that point RedisService.Floaters collection appears to be empty, even though I can clearly see the data in Redis console. I can use the type with Vec included to add new objects to Redis, but the collection is always empty.
I incorrectly reported this as Hot Chocolate bug ChilliCream/graphql-platform#9703 . That contains more complete sample code and an excellent analysis by @glen-84 showing the root cause in Redis.OM. Specifically:
The vector secondary index changes how IRedisCollection builds its underlying FT.SEARCH query, and a plain enumeration stops returning the document even though it is present in Redis. Hot Chocolate is just relaying whatever that IQueryable produces.
If I'm using the index or interface the wrong way I'd appreciate some guidance on what I should change.
---- Floater.cs ----
using Redis.OM;
using Redis.OM.Modeling;
using Redis.OM.Modeling.Vectors;
[Document(StorageType = StorageType.Json, Prefixes = ["Floater"])]
public class Floater
{
[RedisIdField]
[Indexed]
[ID]
public string Id { get; set; } = string.Empty;
[Searchable]
public string? Text { get; set; }
// step3: uncomment the next line
//[Indexed(DistanceMetric = DistanceMetric.L2)]
// step2: uncomment the next line
//[FloatVectorizer(dim: 2)]
// step 1a: uncomment the next line
//public required Vector<float[]> Vec { get; set; }
}
---- RedisService.cs ----
using Redis.OM;
using Redis.OM.Searching;
public class RedisService
{
private readonly RedisConnectionProvider conn;
public RedisService(IConfiguration config)
{
var cs = config["REDIS_CONNECTION_STRING"] ?? "redis://redis:6379";
this.conn = new RedisConnectionProvider(cs);
Floaters = conn.RedisCollection<Floater>();
conn.Connection.CreateIndex(typeof(Floater));
}
public IRedisCollection<Floater> Floaters { get; private set; }
}
Activity
Fix Vector<float[]> serialization with FloatVectorizer (#566) (#569)
Fix non-generic IEnumerable enumeration of RedisCollection (#566)