Update README with LanceDB examples
Browse files
README.md
CHANGED
|
@@ -59,6 +59,18 @@ ds = lance.dataset("hf://datasets/lance-format/pascal-voc-2012-segmentation-lanc
|
|
| 59 |
print(ds.count_rows(), ds.schema.names, ds.list_indices())
|
| 60 |
```
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
## Working with images and masks
|
| 63 |
|
| 64 |
```python
|
|
@@ -94,6 +106,26 @@ neighbors = ds.scanner(
|
|
| 94 |
).to_table().to_pylist()
|
| 95 |
```
|
| 96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
## Why Lance?
|
| 98 |
|
| 99 |
- One dataset carries images + masks + embeddings + indices — no sidecar files.
|
|
|
|
| 59 |
print(ds.count_rows(), ds.schema.names, ds.list_indices())
|
| 60 |
```
|
| 61 |
|
| 62 |
+
## Load with LanceDB
|
| 63 |
+
|
| 64 |
+
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.
|
| 65 |
+
|
| 66 |
+
```python
|
| 67 |
+
import lancedb
|
| 68 |
+
|
| 69 |
+
db = lancedb.connect("hf://datasets/lance-format/pascal-voc-2012-segmentation-lance/data")
|
| 70 |
+
tbl = db.open_table("train")
|
| 71 |
+
print(f"LanceDB table opened with {len(tbl)} image-mask pairs")
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
## Working with images and masks
|
| 75 |
|
| 76 |
```python
|
|
|
|
| 106 |
).to_table().to_pylist()
|
| 107 |
```
|
| 108 |
|
| 109 |
+
### LanceDB vector search
|
| 110 |
+
|
| 111 |
+
```python
|
| 112 |
+
import lancedb
|
| 113 |
+
|
| 114 |
+
db = lancedb.connect("hf://datasets/lance-format/pascal-voc-2012-segmentation-lance/data")
|
| 115 |
+
tbl = db.open_table("train")
|
| 116 |
+
|
| 117 |
+
ref = tbl.search().limit(1).select(["image_emb"]).to_list()[0]
|
| 118 |
+
query_embedding = ref["image_emb"]
|
| 119 |
+
|
| 120 |
+
results = (
|
| 121 |
+
tbl.search(query_embedding)
|
| 122 |
+
.metric("cosine")
|
| 123 |
+
.select(["id"])
|
| 124 |
+
.limit(5)
|
| 125 |
+
.to_list()
|
| 126 |
+
)
|
| 127 |
+
```
|
| 128 |
+
|
| 129 |
## Why Lance?
|
| 130 |
|
| 131 |
- One dataset carries images + masks + embeddings + indices — no sidecar files.
|