Skip to content
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

perf(lance): add prefilter, nprobes, refine_factor to get better result #22066

Merged
merged 1 commit into from
Dec 28, 2024
Merged
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
15 changes: 13 additions & 2 deletions data-storage/lance/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,25 @@ def main() -> None:
)

# Find 5 nearest neighbors
# Note: For better accuracy, you can use nprobes (5-10% of dataset) and refine_factor
k = 5

# nprobes:
# The number of probes determines the distribution of vector space.
# While a higher number enhances search accuracy, it also results in slower performance.
# Typically, setting nprobes to cover 5–10% of the dataset proves effective in achieving high recall with minimal latency.
#
# refine_factor:
# Refine the results by reading extra elements and re-ranking them in memory.
# A higher number makes the search more accurate but also slower.
results = dataset.to_table(
prefilter=True,
nearest={
"column": "vector",
"k": k,
"q": query_vector,
}
"nprobes": 500,
"refine_factor": 10,
},
).to_pandas()

logging.info("Nearest neighbors (distances show similarity, lower = more similar):")
Expand Down