julien-c HF Staff commited on
Commit
e77ba5c
·
verified ·
1 Parent(s): 149dc76

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +30 -0
README.md CHANGED
@@ -55,6 +55,36 @@ Output:
55
  microsoft/IMAGE_UNDERSTANDING 6 1833
56
  ```
57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  ## Why Lance?
59
 
60
  Lance is a modern columnar data format optimized for ML workflows:
 
55
  microsoft/IMAGE_UNDERSTANDING 6 1833
56
  ```
57
 
58
+ ### Example: Vector similarity search
59
+
60
+ ```python
61
+ import lance
62
+ import numpy as np
63
+
64
+ ds = lance.dataset("hf://datasets/julien-c/hub-stats-lance/datasets.lance")
65
+
66
+ # Get an embedding to use as query (e.g., from microsoft/ms_marco)
67
+ query_row = ds.to_table(filter="id = 'microsoft/ms_marco'").to_pandas()
68
+ query_embedding = np.array(query_row["embedding"].iloc[0])
69
+
70
+ # Find 10 nearest neighbors
71
+ results = ds.to_table(
72
+ nearest={"column": "embedding", "q": query_embedding, "k": 10}
73
+ ).to_pandas()
74
+
75
+ print(results[["id", "likes", "downloads", "_distance"]])
76
+ ```
77
+
78
+ Output:
79
+ ```
80
+ id likes downloads _distance
81
+ microsoft/ms_marco 221 11120 2.23
82
+ jiwonii97/atalk_as3 0 0 10.61
83
+ AI-Art-Collab/ae5 0 1 10.85
84
+ wgwgwgwgw/dbbdbbd 0 9 10.90
85
+ 1FDSFS/56803 0 8 10.94
86
+ ```
87
+
88
  ## Why Lance?
89
 
90
  Lance is a modern columnar data format optimized for ML workflows: