Skip to content
Open
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
18 changes: 18 additions & 0 deletions examples/search-knn.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,22 @@ console.log(JSON.stringify(results, null, 2));
// }
// ]
// }

// The inverse of tobytes, for parsing results out of hget.
const frombytes = (buffer) => {
const array = new Float32Array(buffer.length / 4);
for (let i = 0; i < array.length; i++) {
array[i] = buffer.readFloatLE(i * 4);
}
return array;
};

// An example of how to get a particular vector back out of Redis.
const vector = await client.hGet(
commandOptions({ returnBuffers: true }),
'noderedis:knn:a',
'v'
);
console.log(frombytes(vector));

await client.quit();