Feedback: VLINKS return information is incomplete / incorrect
Closed this issue · 5 comments
Page https://redis.io/docs/latest/commands/vlinks
It states:
One of the following:
- Array reply containing the names of adjacent elements as strings; interleved with scores when using the WITHSCORES option.
- Bulk string reply (null bulk string) for unknown keys and/or elements.
I would therefore expect something like:
*2
- $... element1
- $... element2
or (when using WITHSCORES)
*4
- $... element1
- $... 0.123
- $... element2
- $... 0.0012
However, the results are actually nested:
*2
- *0
- *2
- $... element1
- $... element2
or (when using WITHSCORES):
*2
- *0
- *4
- $... element1
- $... 0.123
- $... element2
- $... 0.0012
I have no idea what the first empty array element represents, as it isn't documented.
Checking the implementation, it looks like it is actually
an array of arrays, where each nested array represents one level of neighbors, from highest level to level 0
where the outer dimension is "at each layer in the HNSW graph". Callers don't really interact with the HNSW graph, so it is unclear what insight (if any) we should glean from that, or how many levels we should expect, or the signficance of different levels.
Note also that RESP3 does not change this shape, but does change the types:
*2
- *0
- %4
- $... element1
- ,0.123
- $... element2
- ,0.0012
I suspect that for SE.Redis (.NET), I'm going to flatten this at the library level, i.e. pretend that [[A],[B,C],[D]] was [A,B,C,D].
> del vs
: 0
> vadd vs values 3 1 0 0 element1
: 1
> vadd vs values 3 0.9 0.1 0.0 element2
: 1
> vadd vs values 3 0.0 1.0 0.0 element3
: 1
> vlinks vs element1
* 1
[0]* 2
[0]$ element2
[1]$ element3
> vlinks vs element2
* 2
[0]* (empty)
[1]* 2
[0]$ element1
[1]$ element3
As a side note, and possibly more of a server thing than a doc thing, but: I can also get duplicates, if I loop a until test to failure - I can get results like "element2", "element2", "element3" - very curious
I'm getting a different value for vlinks vs element2 than you are:
vlinks vs element2
*1
*2
$8
element1
$8
element3
No empty array as in your example. 🤷🏻♂️
I'm running 8.2.0 in Docker.
🤷 there's presumably some non-deterministic behaviour here - more of a question for the server folks, but: definitely happens - in my case, using 8.1.240 in docker