Skip to content

KNN example #2352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 18, 2023
Merged

KNN example #2352

merged 3 commits into from
Jan 18, 2023

Conversation

curran
Copy link
Contributor

@curran curran commented Dec 28, 2022

Closes #2351

// Add some sample data...
// https://redis.io/commands/hset/
await Promise.all([
client.hSet('noderedis:vectors:1', { vector: [0.4, -0.325, 4.3] },
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to encode these vectors with Buffer? How should that be done exactly?

@curran curran marked this pull request as ready for review December 29, 2022 01:50
@curran
Copy link
Contributor Author

curran commented Dec 29, 2022

Got it to work! Open to suggestions for cleaning it up.

@curran curran changed the title WIP KNN example KNN example Dec 29, 2022
@leibale
Copy link
Contributor

leibale commented Dec 29, 2022

@curran thanks for contributing! I'll update it to use client.ft.create and client.ft.search (instead of client.sendCommand) later today and then merge it :)

@leibale
Copy link
Contributor

leibale commented Dec 29, 2022

@curran review my changes? 🙏

@codecov-commenter
Copy link

Codecov Report

Base: 95.85% // Head: 95.85% // No change to project coverage 👍

Coverage data is based on head (9953937) compared to base (c5b6f77).
Patch has no changes to coverable lines.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2352   +/-   ##
=======================================
  Coverage   95.85%   95.85%           
=======================================
  Files         449      449           
  Lines        4224     4224           
  Branches      471      471           
=======================================
  Hits         4049     4049           
  Misses        107      107           
  Partials       68       68           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor Author

@curran curran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing! Thank you @leibale for the clean up, this looks fantastic.

]);
await client.ft.create('idx:knn-example', {
v: {
type: SchemaFieldTypes.VECTOR,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice!!! This is exactly what I wanted to do but couldn't figure out the API for. Thank you.

"2",
]);

const results = await client.ft.search('idx:knn-example', '*=>[KNN 4 @v $BLOB AS dist]', {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AMAZING! I could not for the life of me figure out how to formulate this with the ft.search API. This is perfect.

Copy link

@DvirDukhan DvirDukhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you

@leibale leibale merged commit 2042a67 into redis:master Jan 18, 2023
@curran
Copy link
Contributor Author

curran commented Jan 18, 2023

Hooray!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Struggling to invoke KNN vector similarity search
4 participants