prrao87 commited on
Commit
4b4cc78
·
verified ·
1 Parent(s): be6a498

Update README with LanceDB examples

Browse files
Files changed (1) hide show
  1. README.md +57 -0
README.md CHANGED
@@ -68,6 +68,18 @@ ds = lance.dataset("hf://datasets/lance-format/coco-detection-2017-lance/data/va
68
  print(ds.count_rows(), ds.schema.names, ds.list_indices())
69
  ```
70
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  > **Tip — for production use, download locally first.**
72
  > ```bash
73
  > hf download lance-format/coco-detection-2017-lance --repo-type dataset --local-dir ./coco-detection-2017-lance
@@ -112,6 +124,31 @@ busy = ds.scanner(
112
  ).to_table().to_pylist()
113
  ```
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  ## Visual similarity search
116
 
117
  ```python
@@ -129,6 +166,26 @@ neighbors = ds.scanner(
129
  ).to_table().to_pylist()
130
  ```
131
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  ## Why Lance?
133
 
134
  - One dataset carries images + boxes + categories + areas + embeddings + indices — no JSON sidecars.
 
68
  print(ds.count_rows(), ds.schema.names, ds.list_indices())
69
  ```
70
 
71
+ ## Load with LanceDB
72
+
73
+ These tables can also be consumed by [LanceDB](https://lancedb.github.io/lancedb/), the serverless vector database built on Lance, for simplified vector search and other queries.
74
+
75
+ ```python
76
+ import lancedb
77
+
78
+ db = lancedb.connect("hf://datasets/lance-format/coco-detection-2017-lance/data")
79
+ tbl = db.open_table("val")
80
+ print(f"LanceDB table opened with {len(tbl)} images")
81
+ ```
82
+
83
  > **Tip — for production use, download locally first.**
84
  > ```bash
85
  > hf download lance-format/coco-detection-2017-lance --repo-type dataset --local-dir ./coco-detection-2017-lance
 
124
  ).to_table().to_pylist()
125
  ```
126
 
127
+ ### Filter by classes with LanceDB
128
+
129
+ ```python
130
+ import lancedb
131
+
132
+ db = lancedb.connect("hf://datasets/lance-format/coco-detection-2017-lance/data")
133
+ tbl = db.open_table("val")
134
+
135
+ rows = (
136
+ tbl.search()
137
+ .where("array_has_all(categories_present, ['person', 'frisbee'])")
138
+ .select(["image_id", "category_names"])
139
+ .limit(10)
140
+ .to_list()
141
+ )
142
+
143
+ busy = (
144
+ tbl.search()
145
+ .where("num_objects >= 5")
146
+ .select(["image_id", "num_objects"])
147
+ .limit(10)
148
+ .to_list()
149
+ )
150
+ ```
151
+
152
  ## Visual similarity search
153
 
154
  ```python
 
166
  ).to_table().to_pylist()
167
  ```
168
 
169
+ ### LanceDB visual similarity search
170
+
171
+ ```python
172
+ import lancedb
173
+
174
+ db = lancedb.connect("hf://datasets/lance-format/coco-detection-2017-lance/data")
175
+ tbl = db.open_table("val")
176
+
177
+ ref = tbl.search().limit(1).select(["image_emb"]).to_list()[0]
178
+ query_embedding = ref["image_emb"]
179
+
180
+ results = (
181
+ tbl.search(query_embedding)
182
+ .metric("cosine")
183
+ .select(["image_id", "category_names"])
184
+ .limit(5)
185
+ .to_list()
186
+ )
187
+ ```
188
+
189
  ## Why Lance?
190
 
191
  - One dataset carries images + boxes + categories + areas + embeddings + indices — no JSON sidecars.