prrao87 commited on
Commit
314428e
·
verified ·
1 Parent(s): 6dad3be

Update README with LanceDB examples

Browse files
Files changed (1) hide show
  1. README.md +65 -0
README.md CHANGED
@@ -62,6 +62,18 @@ ds = lance.dataset("hf://datasets/lance-format/squad-v2-lance/data/validation.la
62
  print(ds.count_rows(), ds.schema.names, ds.list_indices())
63
  ```
64
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  ## Semantic question retrieval
66
 
67
  ```python
@@ -82,6 +94,27 @@ hits = ds.scanner(
82
  ).to_table().to_pylist()
83
  ```
84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  ## Full-text search on contexts
86
 
87
  ```python
@@ -93,6 +126,22 @@ hits = ds.scanner(
93
  ).to_table().to_pylist()
94
  ```
95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  ## Filter answerable vs impossible questions
97
 
98
  ```python
@@ -100,6 +149,22 @@ ds = lance.dataset("hf://datasets/lance-format/squad-v2-lance/data/validation.la
100
  impossible = ds.scanner(filter="is_impossible = true", columns=["question"], limit=5).to_table()
101
  ```
102
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  ## Why Lance?
104
 
105
  - One dataset carries questions + contexts + answers + embeddings + indices — no sidecar files.
 
62
  print(ds.count_rows(), ds.schema.names, ds.list_indices())
63
  ```
64
 
65
+ ## Load with LanceDB
66
+
67
+ 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.
68
+
69
+ ```python
70
+ import lancedb
71
+
72
+ db = lancedb.connect("hf://datasets/lance-format/squad-v2-lance/data")
73
+ tbl = db.open_table("validation")
74
+ print(f"LanceDB table opened with {len(tbl)} questions")
75
+ ```
76
+
77
  ## Semantic question retrieval
78
 
79
  ```python
 
94
  ).to_table().to_pylist()
95
  ```
96
 
97
+ ### LanceDB semantic question retrieval
98
+
99
+ ```python
100
+ import lancedb
101
+ from sentence_transformers import SentenceTransformer
102
+
103
+ encoder = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2", device="cuda")
104
+ q_vec = encoder.encode(["what year was the eiffel tower built?"], normalize_embeddings=True)[0]
105
+
106
+ db = lancedb.connect("hf://datasets/lance-format/squad-v2-lance/data")
107
+ tbl = db.open_table("train")
108
+
109
+ results = (
110
+ tbl.search(q_vec.tolist(), vector_column_name="question_emb")
111
+ .metric("cosine")
112
+ .select(["id", "title", "question", "answers"])
113
+ .limit(10)
114
+ .to_list()
115
+ )
116
+ ```
117
+
118
  ## Full-text search on contexts
119
 
120
  ```python
 
126
  ).to_table().to_pylist()
127
  ```
128
 
129
+ ### LanceDB full-text search
130
+
131
+ ```python
132
+ import lancedb
133
+
134
+ db = lancedb.connect("hf://datasets/lance-format/squad-v2-lance/data")
135
+ tbl = db.open_table("train")
136
+
137
+ results = (
138
+ tbl.search("great pyramid of giza")
139
+ .select(["title", "question", "context"])
140
+ .limit(5)
141
+ .to_list()
142
+ )
143
+ ```
144
+
145
  ## Filter answerable vs impossible questions
146
 
147
  ```python
 
149
  impossible = ds.scanner(filter="is_impossible = true", columns=["question"], limit=5).to_table()
150
  ```
151
 
152
+ ### Filter with LanceDB
153
+
154
+ ```python
155
+ import lancedb
156
+
157
+ db = lancedb.connect("hf://datasets/lance-format/squad-v2-lance/data")
158
+ tbl = db.open_table("validation")
159
+ impossible = (
160
+ tbl.search()
161
+ .where("is_impossible = true")
162
+ .select(["question"])
163
+ .limit(5)
164
+ .to_list()
165
+ )
166
+ ```
167
+
168
  ## Why Lance?
169
 
170
  - One dataset carries questions + contexts + answers + embeddings + indices — no sidecar files.