prrao87 commited on
Commit
61ca508
·
verified ·
1 Parent(s): f436e94

Update README with LanceDB examples

Browse files
Files changed (1) hide show
  1. README.md +40 -1
README.md CHANGED
@@ -2,7 +2,7 @@
2
  license: mit
3
  task_categories:
4
  - image-classification
5
- - image-retrieval
6
  language:
7
  - en
8
  tags:
@@ -102,6 +102,28 @@ neighbors = ds.scanner(
102
  print(neighbors)
103
  ```
104
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  ## Filter by class
106
 
107
  ```python
@@ -110,6 +132,23 @@ sevens = ds.scanner(filter="label = 7", columns=["id"], limit=10).to_table()
110
  print(sevens)
111
  ```
112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  ## Working with images
114
 
115
  ```python
 
2
  license: mit
3
  task_categories:
4
  - image-classification
5
+ - image-feature-extraction
6
  language:
7
  - en
8
  tags:
 
102
  print(neighbors)
103
  ```
104
 
105
+ ### LanceDB vector search
106
+
107
+ ```python
108
+ import lancedb
109
+
110
+ db = lancedb.connect("hf://datasets/lance-format/mnist-lance/data")
111
+ tbl = db.open_table("train")
112
+
113
+ ref = tbl.search().limit(1).select(["image_emb"]).to_list()[0]
114
+ query_embedding = ref["image_emb"]
115
+
116
+ results = (
117
+ tbl.search(query_embedding)
118
+ .metric("cosine")
119
+ .select(["id", "label", "label_name"])
120
+ .limit(5)
121
+ .to_list()
122
+ )
123
+ for row in results:
124
+ print(row["id"], row["label"], row["label_name"])
125
+ ```
126
+
127
  ## Filter by class
128
 
129
  ```python
 
132
  print(sevens)
133
  ```
134
 
135
+ ### Filter by class with LanceDB
136
+
137
+ ```python
138
+ import lancedb
139
+
140
+ db = lancedb.connect("hf://datasets/lance-format/mnist-lance/data")
141
+ tbl = db.open_table("train")
142
+ sevens = (
143
+ tbl.search()
144
+ .where("label = 7")
145
+ .select(["id"])
146
+ .limit(10)
147
+ .to_list()
148
+ )
149
+ print(sevens)
150
+ ```
151
+
152
  ## Working with images
153
 
154
  ```python