Compare commits
476 Commits
python-v0.
...
docs_enhan
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8debf26b81 | ||
|
|
d2af9fd81d | ||
|
|
54693e6bec | ||
|
|
73b2977bff | ||
|
|
aec85f7875 | ||
|
|
51f92ecb3d | ||
|
|
5b60412d66 | ||
|
|
53d63966a9 | ||
|
|
5ba87575e7 | ||
|
|
cc5f2136a6 | ||
|
|
78e5fb5451 | ||
|
|
8104c5c18e | ||
|
|
4fbabdeec3 | ||
|
|
eb31d95fef | ||
|
|
3169c36525 | ||
|
|
1b990983b3 | ||
|
|
0c21f91c16 | ||
|
|
7e50c239eb | ||
|
|
24e8043150 | ||
|
|
990440385d | ||
|
|
a693a9d897 | ||
|
|
82936c77ef | ||
|
|
dddcddcaf9 | ||
|
|
a9727eb318 | ||
|
|
48d55bf952 | ||
|
|
d2e71c8b08 | ||
|
|
f53aace89c | ||
|
|
d982ee934a | ||
|
|
57605a2d86 | ||
|
|
738511c5f2 | ||
|
|
0b0f42537e | ||
|
|
e412194008 | ||
|
|
a9088224c5 | ||
|
|
688c57a0d8 | ||
|
|
12a98deded | ||
|
|
e4bb042918 | ||
|
|
04e1662681 | ||
|
|
ce2242e06d | ||
|
|
778339388a | ||
|
|
7f8637a0b4 | ||
|
|
09cd08222d | ||
|
|
a248d7feec | ||
|
|
cc9473a94a | ||
|
|
d77e95a4f4 | ||
|
|
62f053ac92 | ||
|
|
34e10caad2 | ||
|
|
f5726e2d0c | ||
|
|
12b4fb42fc | ||
|
|
1328cd46f1 | ||
|
|
0c940ed9f8 | ||
|
|
5f59e51583 | ||
|
|
8d0ea29f89 | ||
|
|
b9468bb980 | ||
|
|
a42df158a3 | ||
|
|
9df6905d86 | ||
|
|
3ffed89793 | ||
|
|
f150768739 | ||
|
|
b432ecf2f6 | ||
|
|
d1a7257810 | ||
|
|
5c5e23bbb9 | ||
|
|
e5796a4836 | ||
|
|
b9c5323265 | ||
|
|
e41a52863a | ||
|
|
13acc8a480 | ||
|
|
22b9eceb12 | ||
|
|
5f62302614 | ||
|
|
d84e0d1db8 | ||
|
|
ac94b2a420 | ||
|
|
b49bc113c4 | ||
|
|
77b5b1cf0e | ||
|
|
e910809de0 | ||
|
|
90b5b55126 | ||
|
|
488e4f8452 | ||
|
|
ba6f949515 | ||
|
|
3dd8522bc9 | ||
|
|
e01ef63488 | ||
|
|
a6cf24b359 | ||
|
|
9a07c9aad8 | ||
|
|
d405798952 | ||
|
|
e8a8b92b2a | ||
|
|
66362c6506 | ||
|
|
5228ca4b6b | ||
|
|
dcc216a244 | ||
|
|
a7aa168c7f | ||
|
|
7a89b5ec68 | ||
|
|
ee862abd29 | ||
|
|
4e1ed2b139 | ||
|
|
008e0b1a93 | ||
|
|
82cbcf6d07 | ||
|
|
1cd5426aea | ||
|
|
41f0e32a06 | ||
|
|
ccfd043939 | ||
|
|
b4d451ed21 | ||
|
|
4c303ba293 | ||
|
|
66eaa2a00e | ||
|
|
5f14a411af | ||
|
|
bea3cef627 | ||
|
|
0e92a7277c | ||
|
|
83ed8d1e49 | ||
|
|
a1ab549457 | ||
|
|
3ba1618be9 | ||
|
|
9a9fc77a95 | ||
|
|
c89d5e6e6d | ||
|
|
d012db24c2 | ||
|
|
7af213801a | ||
|
|
8f54cfcde9 | ||
|
|
119b928a52 | ||
|
|
8bcdc81fd3 | ||
|
|
39e14c70c5 | ||
|
|
af8263af94 | ||
|
|
be4ab9eef3 | ||
|
|
184d2bc969 | ||
|
|
ff6f005336 | ||
|
|
49333e522c | ||
|
|
44eba363b5 | ||
|
|
4568df422d | ||
|
|
a90358a1e3 | ||
|
|
f7f9beaf31 | ||
|
|
cfdbddc5cf | ||
|
|
88affc1428 | ||
|
|
a7be064f00 | ||
|
|
707df47c3f | ||
|
|
6e97fada13 | ||
|
|
3f66be666d | ||
|
|
eda4c587fc | ||
|
|
91d64d86e0 | ||
|
|
ff81c0d698 | ||
|
|
fcfb4587bb | ||
|
|
f43c06d9ce | ||
|
|
ba01d274eb | ||
|
|
615c469af2 | ||
|
|
a649b3b1e4 | ||
|
|
be76242884 | ||
|
|
f4994cb0ec | ||
|
|
00b0c75710 | ||
|
|
47299385fa | ||
|
|
9dea884a7f | ||
|
|
85f8cf20aa | ||
|
|
5e720b2776 | ||
|
|
30a8223944 | ||
|
|
5b1587d84a | ||
|
|
78bafb3007 | ||
|
|
4417f7c5a7 | ||
|
|
577d6ea16e | ||
|
|
53d2ef5e81 | ||
|
|
e48ceb2ebd | ||
|
|
327692ccb1 | ||
|
|
bc224a6a0b | ||
|
|
2dcb39f556 | ||
|
|
6bda6f2f2a | ||
|
|
a3fafd6b54 | ||
|
|
dc8d6835c0 | ||
|
|
f55d99cec5 | ||
|
|
3d8b2f5531 | ||
|
|
b71aa4117f | ||
|
|
55db26f59a | ||
|
|
7e42f58dec | ||
|
|
2790b19279 | ||
|
|
4ba655d05e | ||
|
|
986891db98 | ||
|
|
036bf02901 | ||
|
|
4e31f0cc7a | ||
|
|
0a16e29b93 | ||
|
|
cf7d7a19f5 | ||
|
|
fe2fb91a8b | ||
|
|
81af350d85 | ||
|
|
99adfe065a | ||
|
|
277406509e | ||
|
|
63411b4d8b | ||
|
|
d998f80b04 | ||
|
|
629379a532 | ||
|
|
821cf0e434 | ||
|
|
99ba5331f0 | ||
|
|
121687231c | ||
|
|
ac40d4b235 | ||
|
|
c5a52565ac | ||
|
|
b0a88a7286 | ||
|
|
d41d849e0e | ||
|
|
bf5202f196 | ||
|
|
8be2861061 | ||
|
|
0560e3a0e5 | ||
|
|
b83fbfc344 | ||
|
|
60b22d84bf | ||
|
|
7d55a94efd | ||
|
|
4d8e401d34 | ||
|
|
684eb8b087 | ||
|
|
4e3b82feaa | ||
|
|
8e248a9d67 | ||
|
|
065ffde443 | ||
|
|
c3059dc689 | ||
|
|
a9caa5f2d4 | ||
|
|
8411c36b96 | ||
|
|
7773bda7ee | ||
|
|
392777952f | ||
|
|
7e75e50d3a | ||
|
|
4b8af261a3 | ||
|
|
c8728d4ca1 | ||
|
|
446f837335 | ||
|
|
8f9ad978f5 | ||
|
|
0df38341d5 | ||
|
|
60260018cf | ||
|
|
bb100c5c19 | ||
|
|
eab9072bb5 | ||
|
|
ee1d0b596f | ||
|
|
38a4524893 | ||
|
|
ee0f0611d9 | ||
|
|
34966312cb | ||
|
|
756188358c | ||
|
|
dc5126d8d1 | ||
|
|
50c20af060 | ||
|
|
0965d7dd5a | ||
|
|
7bbb2872de | ||
|
|
e81d2975da | ||
|
|
2c7f96ba4f | ||
|
|
f9dd7a5d8a | ||
|
|
1d4943688d | ||
|
|
7856a94d2c | ||
|
|
371d2f979e | ||
|
|
fff8e399a3 | ||
|
|
73e4015797 | ||
|
|
5142a27482 | ||
|
|
81df2a524e | ||
|
|
40638e5515 | ||
|
|
018314a5c1 | ||
|
|
409eb30ea5 | ||
|
|
ff9872fd44 | ||
|
|
a0608044a1 | ||
|
|
2e4ea7d2bc | ||
|
|
57e5695a54 | ||
|
|
ce58ea7c38 | ||
|
|
57207eff4a | ||
|
|
2d78bff120 | ||
|
|
7c09b9b9a9 | ||
|
|
bd0034a157 | ||
|
|
144b3b5d83 | ||
|
|
b6f0a31686 | ||
|
|
9ec526f73f | ||
|
|
600bfd7237 | ||
|
|
d087e7891d | ||
|
|
098e397cf0 | ||
|
|
63ee8fa6a1 | ||
|
|
693091db29 | ||
|
|
dca4533dbe | ||
|
|
f6bbe199dc | ||
|
|
366e522c2b | ||
|
|
244b6919cc | ||
|
|
aca785ff98 | ||
|
|
bbdebf2c38 | ||
|
|
1336cce0dc | ||
|
|
6c83b6a513 | ||
|
|
6bec4bec51 | ||
|
|
23d30dfc78 | ||
|
|
94c8c50f96 | ||
|
|
72765d8e1a | ||
|
|
a2a8f9615e | ||
|
|
b085d9aaa1 | ||
|
|
6eb662de9b | ||
|
|
2bb2bb581a | ||
|
|
38321fa226 | ||
|
|
22749c3fa2 | ||
|
|
123a49df77 | ||
|
|
a57aa4b142 | ||
|
|
d8e3e54226 | ||
|
|
ccfdf4853a | ||
|
|
87e5d86e90 | ||
|
|
1cf8a3e4e0 | ||
|
|
5372843281 | ||
|
|
54677b8f0b | ||
|
|
ebcf9bf6ae | ||
|
|
797514bcbf | ||
|
|
1c872ce501 | ||
|
|
479f471c14 | ||
|
|
ae0d2f2599 | ||
|
|
1e8678f11a | ||
|
|
662968559d | ||
|
|
9d895801f2 | ||
|
|
80613a40fd | ||
|
|
d43ef7f11e | ||
|
|
554e068917 | ||
|
|
567734dd6e | ||
|
|
1589499f89 | ||
|
|
682e95fa83 | ||
|
|
1ad5e7f2f0 | ||
|
|
ddb3ef4ce5 | ||
|
|
ef20b2a138 | ||
|
|
2e0f251bfd | ||
|
|
2cb91e818d | ||
|
|
2835c76336 | ||
|
|
8068a2bbc3 | ||
|
|
24111d543a | ||
|
|
7eec2b8f9a | ||
|
|
b2b70ea399 | ||
|
|
e50a3c1783 | ||
|
|
b517134309 | ||
|
|
6fb539b5bf | ||
|
|
f37fe120fd | ||
|
|
2e115acb9a | ||
|
|
27a638362d | ||
|
|
22a6695d7a | ||
|
|
57eff82ee7 | ||
|
|
7732f7d41c | ||
|
|
5ca98c326f | ||
|
|
b55db397eb | ||
|
|
c04d72ac8a | ||
|
|
28b02fb72a | ||
|
|
f3cf986777 | ||
|
|
c73fcc8898 | ||
|
|
cd9debc3b7 | ||
|
|
26a97ba997 | ||
|
|
ce19fedb08 | ||
|
|
14e8e48de2 | ||
|
|
c30faf6083 | ||
|
|
64a4f025bb | ||
|
|
6dc968e7d3 | ||
|
|
06b5b69f1e | ||
|
|
6bd3a838fc | ||
|
|
f36fea8f20 | ||
|
|
0a30591729 | ||
|
|
0ed39b6146 | ||
|
|
a8c7f80073 | ||
|
|
0293bbe142 | ||
|
|
7372656369 | ||
|
|
d46bc5dd6e | ||
|
|
86efb11572 | ||
|
|
bb01ad5290 | ||
|
|
1b8cda0941 | ||
|
|
bc85a749a3 | ||
|
|
02c35d3457 | ||
|
|
345c136cfb | ||
|
|
043e388254 | ||
|
|
fe64fc4671 | ||
|
|
6d66404506 | ||
|
|
eff94ecea8 | ||
|
|
7dfb555fea | ||
|
|
f762a669e7 | ||
|
|
0bdc7140dd | ||
|
|
8f6e955b24 | ||
|
|
1096da09da | ||
|
|
683824f1e9 | ||
|
|
db7bdefe77 | ||
|
|
e41894b071 | ||
|
|
e1ae2bcbd8 | ||
|
|
ababc3f8ec | ||
|
|
a1377afcaa | ||
|
|
a26c8f3316 | ||
|
|
88d8d7249e | ||
|
|
0eb7c9ea0c | ||
|
|
1db66c6980 | ||
|
|
c58da8fc8a | ||
|
|
448c4a835d | ||
|
|
850f80de99 | ||
|
|
a022368426 | ||
|
|
8b815ef5a8 | ||
|
|
e4c3a9346c | ||
|
|
1d1f8964d2 | ||
|
|
d326146a40 | ||
|
|
693bca1eba | ||
|
|
343e274ea5 | ||
|
|
a695fb8030 | ||
|
|
bc8670d7af | ||
|
|
74004161ff | ||
|
|
34ddb1de6d | ||
|
|
1029fc9cb0 | ||
|
|
31c5df6d99 | ||
|
|
dbf37a0434 | ||
|
|
f20f19b804 | ||
|
|
55207ce844 | ||
|
|
c21f9cdda0 | ||
|
|
bc38abb781 | ||
|
|
731f86e44c | ||
|
|
31dad71c94 | ||
|
|
9585f550b3 | ||
|
|
8dc2315479 | ||
|
|
f6bfb5da11 | ||
|
|
661fcecf38 | ||
|
|
07fe284810 | ||
|
|
800bb691c3 | ||
|
|
ec24e09add | ||
|
|
0554db03b3 | ||
|
|
b315ea3978 | ||
|
|
aa7806cf0d | ||
|
|
6799613109 | ||
|
|
0f26915d22 | ||
|
|
32163063dc | ||
|
|
9a9a73a65d | ||
|
|
52fa7f5577 | ||
|
|
0cba0f4f92 | ||
|
|
8391ffee84 | ||
|
|
fe8848efb9 | ||
|
|
213c313b99 | ||
|
|
157e995a43 | ||
|
|
ab97e5d632 | ||
|
|
87e9a0250f | ||
|
|
e587a17a64 | ||
|
|
2f1f9f6338 | ||
|
|
a34fa4df26 | ||
|
|
e20979b335 | ||
|
|
08689c345d | ||
|
|
909b7e90cd | ||
|
|
ae8486cc8f | ||
|
|
b8f32d082f | ||
|
|
ea7522baa5 | ||
|
|
8764741116 | ||
|
|
cc916389a6 | ||
|
|
3d7d903d88 | ||
|
|
cc5e2d3e10 | ||
|
|
30f5bc5865 | ||
|
|
2737315cb2 | ||
|
|
d52422603c | ||
|
|
f35f8e451f | ||
|
|
0b9924b432 | ||
|
|
ba416a571d | ||
|
|
13317ffb46 | ||
|
|
ca961567fe | ||
|
|
31a12a141d | ||
|
|
e3061d4cb4 | ||
|
|
1fcc67fd2c | ||
|
|
ac18812af0 | ||
|
|
8324e0f171 | ||
|
|
f0bcb26f32 | ||
|
|
b281c5255c | ||
|
|
d349d2a44a | ||
|
|
0699a6fa7b | ||
|
|
b1a5c251ba | ||
|
|
722462c38b | ||
|
|
902a402951 | ||
|
|
2f2cb984d4 | ||
|
|
9921b2a4e5 | ||
|
|
03b8f99dca | ||
|
|
aa91f35a28 | ||
|
|
f227658e08 | ||
|
|
fd65887d87 | ||
|
|
4673958543 | ||
|
|
a54d1e5618 | ||
|
|
8f7264f81d | ||
|
|
44b8271fde | ||
|
|
74ef141b9c | ||
|
|
b69b1e3ec8 | ||
|
|
bbfadfe58d | ||
|
|
cf977866d8 | ||
|
|
3ff3068a1e | ||
|
|
593b5939be | ||
|
|
f0e1290ae6 | ||
|
|
4b45128bd6 | ||
|
|
b06e214d29 | ||
|
|
c1f8feb6ed | ||
|
|
cada35d5b7 | ||
|
|
2d25c263e9 | ||
|
|
bcd7f66dc7 | ||
|
|
1daecac648 | ||
|
|
b8e656b2a7 | ||
|
|
ff7c1193a7 | ||
|
|
6d70e7c29b | ||
|
|
73cc12ecc5 | ||
|
|
6036cf48a7 | ||
|
|
15f4787cc8 | ||
|
|
0e4050e706 | ||
|
|
147796ffcd | ||
|
|
6fd465ceef | ||
|
|
e2e5a0fb83 | ||
|
|
ff8d5a6d51 | ||
|
|
8829988ada | ||
|
|
80a32be121 | ||
|
|
8325979bb8 | ||
|
|
ed5ff5a482 | ||
|
|
2c9371dcc4 | ||
|
|
6d5621da4a | ||
|
|
380c1572f3 | ||
|
|
4383848d53 | ||
|
|
473c43860c | ||
|
|
17cf244e53 | ||
|
|
0b60694df4 | ||
|
|
600da476e8 | ||
|
|
458217783c | ||
|
|
21b1a71a6b | ||
|
|
2d899675e8 |
@@ -1,5 +1,5 @@
|
|||||||
[bumpversion]
|
[bumpversion]
|
||||||
current_version = 0.1.15
|
current_version = 0.4.10
|
||||||
commit = True
|
commit = True
|
||||||
message = Bump version: {current_version} → {new_version}
|
message = Bump version: {current_version} → {new_version}
|
||||||
tag = True
|
tag = True
|
||||||
|
|||||||
35
.cargo/config.toml
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
[profile.release]
|
||||||
|
lto = "fat"
|
||||||
|
codegen-units = 1
|
||||||
|
|
||||||
|
[profile.release-with-debug]
|
||||||
|
inherits = "release"
|
||||||
|
debug = true
|
||||||
|
# Prioritize compile time over runtime performance
|
||||||
|
codegen-units = 16
|
||||||
|
lto = "thin"
|
||||||
|
|
||||||
|
[target.'cfg(all())']
|
||||||
|
rustflags = [
|
||||||
|
"-Wclippy::all",
|
||||||
|
"-Wclippy::style",
|
||||||
|
"-Wclippy::fallible_impl_from",
|
||||||
|
"-Wclippy::manual_let_else",
|
||||||
|
"-Wclippy::redundant_pub_crate",
|
||||||
|
"-Wclippy::string_add_assign",
|
||||||
|
"-Wclippy::string_add",
|
||||||
|
"-Wclippy::string_lit_as_bytes",
|
||||||
|
"-Wclippy::string_to_string",
|
||||||
|
"-Wclippy::use_self",
|
||||||
|
"-Dclippy::cargo",
|
||||||
|
"-Dclippy::dbg_macro",
|
||||||
|
# not too much we can do to avoid multiple crate versions
|
||||||
|
"-Aclippy::multiple-crate-versions",
|
||||||
|
"-Aclippy::wildcard_dependencies",
|
||||||
|
]
|
||||||
|
|
||||||
|
[target.x86_64-unknown-linux-gnu]
|
||||||
|
rustflags = ["-C", "target-cpu=haswell", "-C", "target-feature=+avx2,+fma,+f16c"]
|
||||||
|
|
||||||
|
[target.aarch64-apple-darwin]
|
||||||
|
rustflags = ["-C", "target-cpu=apple-m1", "-C", "target-feature=+neon,+fp16,+fhm,+dotprod"]
|
||||||
33
.github/ISSUE_TEMPLATE/bug-node.yml
vendored
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
name: Bug Report - Node / Typescript
|
||||||
|
description: File a bug report
|
||||||
|
title: "bug(node): "
|
||||||
|
labels: [bug, typescript]
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
Thanks for taking the time to fill out this bug report!
|
||||||
|
- type: input
|
||||||
|
id: version
|
||||||
|
attributes:
|
||||||
|
label: LanceDB version
|
||||||
|
description: What version of LanceDB are you using? `npm list | grep vectordb`.
|
||||||
|
placeholder: v0.3.2
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
|
- type: textarea
|
||||||
|
id: what-happened
|
||||||
|
attributes:
|
||||||
|
label: What happened?
|
||||||
|
description: Also tell us, what did you expect to happen?
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: reproduction
|
||||||
|
attributes:
|
||||||
|
label: Are there known steps to reproduce?
|
||||||
|
description: |
|
||||||
|
Let us know how to reproduce the bug and we may be able to fix it more
|
||||||
|
quickly. This is not required, but it is helpful.
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
33
.github/ISSUE_TEMPLATE/bug-python.yml
vendored
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
name: Bug Report - Python
|
||||||
|
description: File a bug report
|
||||||
|
title: "bug(python): "
|
||||||
|
labels: [bug, python]
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
Thanks for taking the time to fill out this bug report!
|
||||||
|
- type: input
|
||||||
|
id: version
|
||||||
|
attributes:
|
||||||
|
label: LanceDB version
|
||||||
|
description: What version of LanceDB are you using? `python -c "import lancedb; print(lancedb.__version__)"`.
|
||||||
|
placeholder: v0.3.2
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
|
- type: textarea
|
||||||
|
id: what-happened
|
||||||
|
attributes:
|
||||||
|
label: What happened?
|
||||||
|
description: Also tell us, what did you expect to happen?
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: reproduction
|
||||||
|
attributes:
|
||||||
|
label: Are there known steps to reproduce?
|
||||||
|
description: |
|
||||||
|
Let us know how to reproduce the bug and we may be able to fix it more
|
||||||
|
quickly. This is not required, but it is helpful.
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
5
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
blank_issues_enabled: true
|
||||||
|
contact_links:
|
||||||
|
- name: Discord Community Support
|
||||||
|
url: https://discord.com/invite/zMM32dvNtd
|
||||||
|
about: Please ask and answer questions here.
|
||||||
23
.github/ISSUE_TEMPLATE/documentation.yml
vendored
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
name: 'Documentation improvement'
|
||||||
|
description: Report an issue with the documentation.
|
||||||
|
labels: [documentation]
|
||||||
|
|
||||||
|
body:
|
||||||
|
- type: textarea
|
||||||
|
id: description
|
||||||
|
attributes:
|
||||||
|
label: Description
|
||||||
|
description: >
|
||||||
|
Describe the issue with the documentation and how it can be fixed or improved.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: input
|
||||||
|
id: link
|
||||||
|
attributes:
|
||||||
|
label: Link
|
||||||
|
description: >
|
||||||
|
Provide a link to the existing documentation, if applicable.
|
||||||
|
placeholder: ex. https://lancedb.github.io/lancedb/guides/tables/...
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
31
.github/ISSUE_TEMPLATE/feature.yml
vendored
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
name: Feature suggestion
|
||||||
|
description: Suggestion a new feature for LanceDB
|
||||||
|
title: "Feature: "
|
||||||
|
labels: [enhancement]
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
Share a new idea for a feature or improvement. Be sure to search existing
|
||||||
|
issues first to avoid duplicates.
|
||||||
|
- type: dropdown
|
||||||
|
id: sdk
|
||||||
|
attributes:
|
||||||
|
label: SDK
|
||||||
|
description: Which SDK are you using? This helps us prioritize.
|
||||||
|
options:
|
||||||
|
- Python
|
||||||
|
- Node
|
||||||
|
- Rust
|
||||||
|
default: 0
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
|
- type: textarea
|
||||||
|
id: description
|
||||||
|
attributes:
|
||||||
|
label: Description
|
||||||
|
description: |
|
||||||
|
Describe the feature and why it would be useful. If applicable, consider
|
||||||
|
providing a code example of what it might be like to use the feature.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
2
.github/workflows/cargo-publish.yml
vendored
@@ -16,7 +16,7 @@ jobs:
|
|||||||
# Only runs on tags that matches the make-release action
|
# Only runs on tags that matches the make-release action
|
||||||
if: startsWith(github.ref, 'refs/tags/v')
|
if: startsWith(github.ref, 'refs/tags/v')
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
with:
|
with:
|
||||||
workspaces: rust
|
workspaces: rust
|
||||||
|
|||||||
11
.github/workflows/docs.yml
vendored
@@ -27,9 +27,9 @@ jobs:
|
|||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v4
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: "3.10"
|
python-version: "3.10"
|
||||||
cache: "pip"
|
cache: "pip"
|
||||||
@@ -42,7 +42,7 @@ jobs:
|
|||||||
- name: Set up node
|
- name: Set up node
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node-version }}
|
node-version: 20
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
cache-dependency-path: node/package-lock.json
|
cache-dependency-path: node/package-lock.json
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
@@ -62,8 +62,9 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
npx typedoc --plugin typedoc-plugin-markdown --out ../docs/src/javascript src/index.ts
|
npx typedoc --plugin typedoc-plugin-markdown --out ../docs/src/javascript src/index.ts
|
||||||
- name: Build docs
|
- name: Build docs
|
||||||
|
working-directory: docs
|
||||||
run: |
|
run: |
|
||||||
PYTHONPATH=. mkdocs build -f docs/mkdocs.yml
|
PYTHONPATH=. mkdocs build
|
||||||
- name: Setup Pages
|
- name: Setup Pages
|
||||||
uses: actions/configure-pages@v2
|
uses: actions/configure-pages@v2
|
||||||
- name: Upload artifact
|
- name: Upload artifact
|
||||||
@@ -72,4 +73,4 @@ jobs:
|
|||||||
path: "docs/site"
|
path: "docs/site"
|
||||||
- name: Deploy to GitHub Pages
|
- name: Deploy to GitHub Pages
|
||||||
id: deployment
|
id: deployment
|
||||||
uses: actions/deploy-pages@v1
|
uses: actions/deploy-pages@v1
|
||||||
|
|||||||
56
.github/workflows/docs_test.yml
vendored
@@ -18,24 +18,20 @@ on:
|
|||||||
env:
|
env:
|
||||||
# Disable full debug symbol generation to speed up CI build and keep memory down
|
# Disable full debug symbol generation to speed up CI build and keep memory down
|
||||||
# "1" means line tables only, which is useful for panic tracebacks.
|
# "1" means line tables only, which is useful for panic tracebacks.
|
||||||
RUSTFLAGS: "-C debuginfo=1"
|
RUSTFLAGS: "-C debuginfo=1 -C target-cpu=native -C target-feature=+f16c,+avx2,+fma"
|
||||||
RUST_BACKTRACE: "1"
|
RUST_BACKTRACE: "1"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test-python:
|
test-python:
|
||||||
name: Test doc python code
|
name: Test doc python code
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: "ubuntu-latest"
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
python-minor-version: [ "11" ]
|
|
||||||
os: ["ubuntu-22.04"]
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v4
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: 3.${{ matrix.python-minor-version }}
|
python-version: 3.11
|
||||||
cache: "pip"
|
cache: "pip"
|
||||||
cache-dependency-path: "docs/test/requirements.txt"
|
cache-dependency-path: "docs/test/requirements.txt"
|
||||||
- name: Build Python
|
- name: Build Python
|
||||||
@@ -52,42 +48,42 @@ jobs:
|
|||||||
for d in *; do cd "$d"; echo "$d".py; python "$d".py; cd ..; done
|
for d in *; do cd "$d"; echo "$d".py; python "$d".py; cd ..; done
|
||||||
test-node:
|
test-node:
|
||||||
name: Test doc nodejs code
|
name: Test doc nodejs code
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: "ubuntu-latest"
|
||||||
|
timeout-minutes: 45
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
fail-fast: false
|
||||||
node-version: [ "18" ]
|
|
||||||
os: ["ubuntu-22.04"]
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
lfs: true
|
lfs: true
|
||||||
- name: Set up Node
|
- name: Set up Node
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node-version }}
|
node-version: 20
|
||||||
- name: Install dependecies needed for ubuntu
|
- name: Install dependecies needed for ubuntu
|
||||||
if: ${{ matrix.os == 'ubuntu-22.04' }}
|
|
||||||
run: |
|
run: |
|
||||||
sudo apt install -y protobuf-compiler libssl-dev
|
sudo apt install -y protobuf-compiler libssl-dev
|
||||||
- name: Install node dependencies
|
|
||||||
run: |
|
|
||||||
cd docs/test
|
|
||||||
npm install
|
|
||||||
- name: Rust cache
|
- name: Rust cache
|
||||||
uses: swatinem/rust-cache@v2
|
uses: swatinem/rust-cache@v2
|
||||||
- name: Install LanceDB
|
- name: Install node dependencies
|
||||||
run: |
|
run: |
|
||||||
cd docs/test/node_modules/vectordb
|
sudo swapoff -a
|
||||||
|
sudo fallocate -l 8G /swapfile
|
||||||
|
sudo chmod 600 /swapfile
|
||||||
|
sudo mkswap /swapfile
|
||||||
|
sudo swapon /swapfile
|
||||||
|
sudo swapon --show
|
||||||
|
cd node
|
||||||
npm ci
|
npm ci
|
||||||
npm run build-release
|
npm run build-release
|
||||||
npm run tsc
|
cd ../docs
|
||||||
- name: Create test files
|
npm install
|
||||||
run: |
|
|
||||||
cd docs/test
|
|
||||||
node md_testing.js
|
|
||||||
- name: Test
|
- name: Test
|
||||||
|
env:
|
||||||
|
LANCEDB_URI: ${{ secrets.LANCEDB_URI }}
|
||||||
|
LANCEDB_DEV_API_KEY: ${{ secrets.LANCEDB_DEV_API_KEY }}
|
||||||
run: |
|
run: |
|
||||||
cd docs/test/node
|
cd docs
|
||||||
for d in *; do cd "$d"; echo "$d".js; node "$d".js; cd ..; done
|
npm t
|
||||||
|
|||||||
20
.github/workflows/make-release-commit.yml
vendored
@@ -26,9 +26,10 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Check out main
|
- name: Check out main
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
ref: main
|
ref: main
|
||||||
|
persist-credentials: false
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
lfs: true
|
lfs: true
|
||||||
- name: Set git configs for bumpversion
|
- name: Set git configs for bumpversion
|
||||||
@@ -36,14 +37,23 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
git config user.name 'Lance Release'
|
git config user.name 'Lance Release'
|
||||||
git config user.email 'lance-dev@lancedb.com'
|
git config user.email 'lance-dev@lancedb.com'
|
||||||
- name: Set up Python 3.10
|
- name: Set up Python 3.11
|
||||||
uses: actions/setup-python@v4
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: "3.10"
|
python-version: "3.11"
|
||||||
- name: Bump version, create tag and commit
|
- name: Bump version, create tag and commit
|
||||||
run: |
|
run: |
|
||||||
pip install bump2version
|
pip install bump2version
|
||||||
bumpversion --verbose ${{ inputs.part }}
|
bumpversion --verbose ${{ inputs.part }}
|
||||||
git push
|
- name: Push new version and tag
|
||||||
|
if: ${{ inputs.dry_run }} == "false"
|
||||||
|
uses: ad-m/github-push-action@master
|
||||||
|
with:
|
||||||
|
github_token: ${{ secrets.LANCEDB_RELEASE_TOKEN }}
|
||||||
|
branch: main
|
||||||
|
tags: true
|
||||||
- uses: ./.github/workflows/update_package_lock
|
- uses: ./.github/workflows/update_package_lock
|
||||||
|
if: ${{ inputs.dry_run }} == "false"
|
||||||
|
with:
|
||||||
|
github_token: ${{ secrets.LANCEDB_RELEASE_TOKEN }}
|
||||||
|
|
||||||
|
|||||||
75
.github/workflows/node.yml
vendored
@@ -9,11 +9,18 @@ on:
|
|||||||
- node/**
|
- node/**
|
||||||
- rust/ffi/node/**
|
- rust/ffi/node/**
|
||||||
- .github/workflows/node.yml
|
- .github/workflows/node.yml
|
||||||
|
- docker-compose.yml
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
env:
|
env:
|
||||||
# Disable full debug symbol generation to speed up CI build and keep memory down
|
# Disable full debug symbol generation to speed up CI build and keep memory down
|
||||||
# "1" means line tables only, which is useful for panic tracebacks.
|
# "1" means line tables only, which is useful for panic tracebacks.
|
||||||
RUSTFLAGS: "-C debuginfo=1"
|
#
|
||||||
|
# Use native CPU to accelerate tests if possible, especially for f16
|
||||||
|
RUSTFLAGS: "-C debuginfo=1 -C target-cpu=native -C target-feature=+f16c,+avx2,+fma"
|
||||||
RUST_BACKTRACE: "1"
|
RUST_BACKTRACE: "1"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
@@ -25,13 +32,13 @@ jobs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
working-directory: node
|
working-directory: node
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
lfs: true
|
lfs: true
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: 18
|
node-version: 20
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
cache-dependency-path: node/package-lock.json
|
cache-dependency-path: node/package-lock.json
|
||||||
- name: Lint
|
- name: Lint
|
||||||
@@ -43,14 +50,14 @@ jobs:
|
|||||||
timeout-minutes: 30
|
timeout-minutes: 30
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node-version: [ "16", "18" ]
|
node-version: [ "18", "20" ]
|
||||||
runs-on: "ubuntu-22.04"
|
runs-on: "ubuntu-22.04"
|
||||||
defaults:
|
defaults:
|
||||||
run:
|
run:
|
||||||
shell: bash
|
shell: bash
|
||||||
working-directory: node
|
working-directory: node
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
lfs: true
|
lfs: true
|
||||||
@@ -67,7 +74,6 @@ jobs:
|
|||||||
- name: Build
|
- name: Build
|
||||||
run: |
|
run: |
|
||||||
npm ci
|
npm ci
|
||||||
npm run tsc
|
|
||||||
npm run build
|
npm run build
|
||||||
npm run pack-build
|
npm run pack-build
|
||||||
npm install --no-save ./dist/lancedb-vectordb-*.tgz
|
npm install --no-save ./dist/lancedb-vectordb-*.tgz
|
||||||
@@ -83,13 +89,13 @@ jobs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
working-directory: node
|
working-directory: node
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
lfs: true
|
lfs: true
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: 18
|
node-version: 20
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
cache-dependency-path: node/package-lock.json
|
cache-dependency-path: node/package-lock.json
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
@@ -98,7 +104,6 @@ jobs:
|
|||||||
- name: Build
|
- name: Build
|
||||||
run: |
|
run: |
|
||||||
npm ci
|
npm ci
|
||||||
npm run tsc
|
|
||||||
npm run build
|
npm run build
|
||||||
npm run pack-build
|
npm run pack-build
|
||||||
npm install --no-save ./dist/lancedb-vectordb-*.tgz
|
npm install --no-save ./dist/lancedb-vectordb-*.tgz
|
||||||
@@ -107,3 +112,55 @@ jobs:
|
|||||||
- name: Test
|
- name: Test
|
||||||
run: |
|
run: |
|
||||||
npm run test
|
npm run test
|
||||||
|
aws-integtest:
|
||||||
|
timeout-minutes: 45
|
||||||
|
runs-on: "ubuntu-22.04"
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: bash
|
||||||
|
working-directory: node
|
||||||
|
env:
|
||||||
|
AWS_ACCESS_KEY_ID: ACCESSKEY
|
||||||
|
AWS_SECRET_ACCESS_KEY: SECRETKEY
|
||||||
|
AWS_DEFAULT_REGION: us-west-2
|
||||||
|
# this one is for s3
|
||||||
|
AWS_ENDPOINT: http://localhost:4566
|
||||||
|
# this one is for dynamodb
|
||||||
|
DYNAMODB_ENDPOINT: http://localhost:4566
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
lfs: true
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 20
|
||||||
|
cache: 'npm'
|
||||||
|
cache-dependency-path: node/package-lock.json
|
||||||
|
- name: start local stack
|
||||||
|
run: docker compose -f ../docker-compose.yml up -d --wait
|
||||||
|
- name: create s3
|
||||||
|
run: aws s3 mb s3://lancedb-integtest --endpoint $AWS_ENDPOINT
|
||||||
|
- name: create ddb
|
||||||
|
run: |
|
||||||
|
aws dynamodb create-table \
|
||||||
|
--table-name lancedb-integtest \
|
||||||
|
--attribute-definitions '[{"AttributeName": "base_uri", "AttributeType": "S"}, {"AttributeName": "version", "AttributeType": "N"}]' \
|
||||||
|
--key-schema '[{"AttributeName": "base_uri", "KeyType": "HASH"}, {"AttributeName": "version", "KeyType": "RANGE"}]' \
|
||||||
|
--provisioned-throughput '{"ReadCapacityUnits": 10, "WriteCapacityUnits": 10}' \
|
||||||
|
--endpoint-url $DYNAMODB_ENDPOINT
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install -y protobuf-compiler libssl-dev
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
npm ci
|
||||||
|
npm run build
|
||||||
|
npm run pack-build
|
||||||
|
npm install --no-save ./dist/lancedb-vectordb-*.tgz
|
||||||
|
# Remove index.node to test with dependency installed
|
||||||
|
rm index.node
|
||||||
|
- name: Test
|
||||||
|
run: npm run integration-test
|
||||||
|
|||||||
114
.github/workflows/nodejs.yml
vendored
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
name: NodeJS (NAPI)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
|
paths:
|
||||||
|
- nodejs/**
|
||||||
|
- .github/workflows/nodejs.yml
|
||||||
|
- docker-compose.yml
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
env:
|
||||||
|
# Disable full debug symbol generation to speed up CI build and keep memory down
|
||||||
|
# "1" means line tables only, which is useful for panic tracebacks.
|
||||||
|
RUSTFLAGS: "-C debuginfo=1"
|
||||||
|
RUST_BACKTRACE: "1"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
lint:
|
||||||
|
name: Lint
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: bash
|
||||||
|
working-directory: nodejs
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
lfs: true
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 20
|
||||||
|
cache: 'npm'
|
||||||
|
cache-dependency-path: nodejs/package-lock.json
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install -y protobuf-compiler libssl-dev
|
||||||
|
- name: Lint
|
||||||
|
run: |
|
||||||
|
cargo fmt --all -- --check
|
||||||
|
cargo clippy --all --all-features -- -D warnings
|
||||||
|
npm ci
|
||||||
|
npm run lint
|
||||||
|
linux:
|
||||||
|
name: Linux (NodeJS ${{ matrix.node-version }})
|
||||||
|
timeout-minutes: 30
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
node-version: [ "18", "20" ]
|
||||||
|
runs-on: "ubuntu-22.04"
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: bash
|
||||||
|
working-directory: nodejs
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
lfs: true
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: ${{ matrix.node-version }}
|
||||||
|
cache: 'npm'
|
||||||
|
cache-dependency-path: node/package-lock.json
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install -y protobuf-compiler libssl-dev
|
||||||
|
npm install -g @napi-rs/cli
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
npm ci
|
||||||
|
npm run build
|
||||||
|
- name: Test
|
||||||
|
run: npm run test
|
||||||
|
macos:
|
||||||
|
timeout-minutes: 30
|
||||||
|
runs-on: "macos-14"
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: bash
|
||||||
|
working-directory: nodejs
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
lfs: true
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 20
|
||||||
|
cache: 'npm'
|
||||||
|
cache-dependency-path: node/package-lock.json
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
brew install protobuf
|
||||||
|
npm install -g @napi-rs/cli
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
npm ci
|
||||||
|
npm run build
|
||||||
|
- name: Test
|
||||||
|
run: |
|
||||||
|
npm run test
|
||||||
|
|
||||||
94
.github/workflows/npm-publish.yml
vendored
@@ -15,7 +15,7 @@ jobs:
|
|||||||
working-directory: node
|
working-directory: node
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
node-version: 20
|
||||||
@@ -35,30 +35,31 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
name: node-package
|
name: node-package
|
||||||
path: |
|
path: |
|
||||||
node/lancedb-vectordb-*.tgz
|
node/vectordb-*.tgz
|
||||||
|
|
||||||
node-macos:
|
node-macos:
|
||||||
runs-on: macos-12
|
strategy:
|
||||||
|
matrix:
|
||||||
|
config:
|
||||||
|
- arch: x86_64-apple-darwin
|
||||||
|
runner: macos-13
|
||||||
|
- arch: aarch64-apple-darwin
|
||||||
|
# xlarge is implicitly arm64.
|
||||||
|
runner: macos-14
|
||||||
|
runs-on: ${{ matrix.config.runner }}
|
||||||
# Only runs on tags that matches the make-release action
|
# Only runs on tags that matches the make-release action
|
||||||
if: startsWith(github.ref, 'refs/tags/v')
|
if: startsWith(github.ref, 'refs/tags/v')
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
target: [x86_64-apple-darwin, aarch64-apple-darwin]
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
- name: Install system dependencies
|
- name: Install system dependencies
|
||||||
run: brew install protobuf
|
run: brew install protobuf
|
||||||
- name: Install npm dependencies
|
- name: Install npm dependencies
|
||||||
run: |
|
run: |
|
||||||
cd node
|
cd node
|
||||||
npm ci
|
npm ci
|
||||||
- name: Install rustup target
|
|
||||||
if: ${{ matrix.target == 'aarch64-apple-darwin' }}
|
|
||||||
run: rustup target add aarch64-apple-darwin
|
|
||||||
- name: Build MacOS native node modules
|
- name: Build MacOS native node modules
|
||||||
run: bash ci/build_macos_artifacts.sh ${{ matrix.target }}
|
run: bash ci/build_macos_artifacts.sh ${{ matrix.config.arch }}
|
||||||
- name: Upload Darwin Artifacts
|
- name: Upload Darwin Artifacts
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
@@ -66,49 +67,41 @@ jobs:
|
|||||||
path: |
|
path: |
|
||||||
node/dist/lancedb-vectordb-darwin*.tgz
|
node/dist/lancedb-vectordb-darwin*.tgz
|
||||||
|
|
||||||
|
|
||||||
node-linux:
|
node-linux:
|
||||||
name: node-linux (${{ matrix.arch}}-unknown-linux-${{ matrix.libc }})
|
name: node-linux (${{ matrix.config.arch}}-unknown-linux-gnu
|
||||||
runs-on: ubuntu-latest
|
runs-on: ${{ matrix.config.runner }}
|
||||||
# Only runs on tags that matches the make-release action
|
# Only runs on tags that matches the make-release action
|
||||||
if: startsWith(github.ref, 'refs/tags/v')
|
if: startsWith(github.ref, 'refs/tags/v')
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
libc:
|
config:
|
||||||
- gnu
|
- arch: x86_64
|
||||||
# TODO: re-enable musl once we have refactored to pre-built containers
|
runner: ubuntu-latest
|
||||||
# Right now we have to build node from source which is too expensive.
|
- arch: aarch64
|
||||||
# - musl
|
# For successful fat LTO builds, we need a large runner to avoid OOM errors.
|
||||||
arch:
|
runner: buildjet-16vcpu-ubuntu-2204-arm
|
||||||
- x86_64
|
|
||||||
# Building on aarch64 is too slow for now
|
|
||||||
# - aarch64
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
- name: Change owner to root (for npm)
|
# Buildjet aarch64 runners have only 1.5 GB RAM per core, vs 3.5 GB per core for
|
||||||
# The docker container is run as root, so we need the files to be owned by root
|
# x86_64 runners. To avoid OOM errors on ARM, we create a swap file.
|
||||||
# Otherwise npm is a nightmare: https://github.com/npm/cli/issues/3773
|
- name: Configure aarch64 build
|
||||||
run: sudo chown -R root:root .
|
if: ${{ matrix.config.arch == 'aarch64' }}
|
||||||
- name: Set up QEMU
|
|
||||||
if: ${{ matrix.arch == 'aarch64' }}
|
|
||||||
uses: docker/setup-qemu-action@v2
|
|
||||||
with:
|
|
||||||
platforms: arm64
|
|
||||||
- name: Build Linux GNU native node modules
|
|
||||||
if: ${{ matrix.libc == 'gnu' }}
|
|
||||||
run: |
|
run: |
|
||||||
docker run \
|
free -h
|
||||||
-v $(pwd):/io -w /io \
|
sudo fallocate -l 16G /swapfile
|
||||||
rust:1.70-bookworm \
|
sudo chmod 600 /swapfile
|
||||||
bash ci/build_linux_artifacts.sh ${{ matrix.arch }}-unknown-linux-gnu
|
sudo mkswap /swapfile
|
||||||
- name: Build musl Linux native node modules
|
sudo swapon /swapfile
|
||||||
if: ${{ matrix.libc == 'musl' }}
|
echo "/swapfile swap swap defaults 0 0" >> sudo /etc/fstab
|
||||||
|
# print info
|
||||||
|
swapon --show
|
||||||
|
free -h
|
||||||
|
- name: Build Linux Artifacts
|
||||||
run: |
|
run: |
|
||||||
docker run --platform linux/arm64/v8 \
|
bash ci/build_linux_artifacts.sh ${{ matrix.config.arch }}
|
||||||
-v $(pwd):/io -w /io \
|
|
||||||
quay.io/pypa/musllinux_1_1_${{ matrix.arch }} \
|
|
||||||
bash ci/build_linux_artifacts.sh ${{ matrix.arch }}-unknown-linux-musl
|
|
||||||
- name: Upload Linux Artifacts
|
- name: Upload Linux Artifacts
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
@@ -126,7 +119,7 @@ jobs:
|
|||||||
target: [x86_64-pc-windows-msvc]
|
target: [x86_64-pc-windows-msvc]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
- name: Install Protoc v21.12
|
- name: Install Protoc v21.12
|
||||||
working-directory: C:\
|
working-directory: C:\
|
||||||
run: |
|
run: |
|
||||||
@@ -176,5 +169,12 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: main
|
||||||
|
persist-credentials: false
|
||||||
|
fetch-depth: 0
|
||||||
|
lfs: true
|
||||||
- uses: ./.github/workflows/update_package_lock
|
- uses: ./.github/workflows/update_package_lock
|
||||||
|
with:
|
||||||
|
github_token: ${{ secrets.LANCEDB_RELEASE_TOKEN }}
|
||||||
|
|||||||
4
.github/workflows/pypi-publish.yml
vendored
@@ -14,9 +14,9 @@ jobs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
working-directory: python
|
working-directory: python
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v4
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: "3.8"
|
python-version: "3.8"
|
||||||
- name: Build distribution
|
- name: Build distribution
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Check out main
|
- name: Check out main
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
ref: main
|
ref: main
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
@@ -37,10 +37,10 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
git config user.name 'Lance Release'
|
git config user.name 'Lance Release'
|
||||||
git config user.email 'lance-dev@lancedb.com'
|
git config user.email 'lance-dev@lancedb.com'
|
||||||
- name: Set up Python 3.10
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v4
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: "3.10"
|
python-version: "3.11"
|
||||||
- name: Bump version, create tag and commit
|
- name: Bump version, create tag and commit
|
||||||
working-directory: python
|
working-directory: python
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
77
.github/workflows/python.yml
vendored
@@ -8,61 +8,100 @@ on:
|
|||||||
paths:
|
paths:
|
||||||
- python/**
|
- python/**
|
||||||
- .github/workflows/python.yml
|
- .github/workflows/python.yml
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
linux:
|
linux:
|
||||||
timeout-minutes: 30
|
timeout-minutes: 30
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
python-minor-version: [ "8", "9", "10", "11" ]
|
python-minor-version: [ "8", "11" ]
|
||||||
runs-on: "ubuntu-22.04"
|
runs-on: "ubuntu-22.04"
|
||||||
defaults:
|
defaults:
|
||||||
run:
|
run:
|
||||||
shell: bash
|
shell: bash
|
||||||
working-directory: python
|
working-directory: python
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
lfs: true
|
lfs: true
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v4
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: 3.${{ matrix.python-minor-version }}
|
python-version: 3.${{ matrix.python-minor-version }}
|
||||||
- name: Install lancedb
|
- name: Install lancedb
|
||||||
run: |
|
run: |
|
||||||
pip install -e .
|
pip install -e .[tests]
|
||||||
pip install tantivy@git+https://github.com/quickwit-oss/tantivy-py#164adc87e1a033117001cf70e38c82a53014d985
|
pip install tantivy@git+https://github.com/quickwit-oss/tantivy-py#164adc87e1a033117001cf70e38c82a53014d985
|
||||||
pip install pytest pytest-mock black isort
|
pip install pytest pytest-mock ruff
|
||||||
- name: Black
|
- name: Format check
|
||||||
run: black --check --diff --no-color --quiet .
|
run: ruff format --check .
|
||||||
- name: isort
|
- name: Lint
|
||||||
run: isort --check --diff --quiet .
|
run: ruff .
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: pytest -x -v --durations=30 tests
|
run: pytest -m "not slow" -x -v --durations=30 tests
|
||||||
- name: doctest
|
- name: doctest
|
||||||
run: pytest --doctest-modules lancedb
|
run: pytest --doctest-modules lancedb
|
||||||
mac:
|
platform:
|
||||||
|
name: "Platform: ${{ matrix.config.name }}"
|
||||||
timeout-minutes: 30
|
timeout-minutes: 30
|
||||||
runs-on: "macos-12"
|
strategy:
|
||||||
|
matrix:
|
||||||
|
config:
|
||||||
|
- name: x86 Mac
|
||||||
|
runner: macos-13
|
||||||
|
- name: Arm Mac
|
||||||
|
runner: macos-14
|
||||||
|
- name: x86 Windows
|
||||||
|
runner: windows-latest
|
||||||
|
runs-on: "${{ matrix.config.runner }}"
|
||||||
defaults:
|
defaults:
|
||||||
run:
|
run:
|
||||||
shell: bash
|
shell: bash
|
||||||
working-directory: python
|
working-directory: python
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
lfs: true
|
lfs: true
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v4
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: "3.11"
|
python-version: "3.11"
|
||||||
- name: Install lancedb
|
- name: Install lancedb
|
||||||
run: |
|
run: |
|
||||||
pip install -e .
|
pip install -e .[tests]
|
||||||
pip install tantivy@git+https://github.com/quickwit-oss/tantivy-py#164adc87e1a033117001cf70e38c82a53014d985
|
pip install tantivy@git+https://github.com/quickwit-oss/tantivy-py#164adc87e1a033117001cf70e38c82a53014d985
|
||||||
pip install pytest pytest-mock black
|
pip install pytest pytest-mock
|
||||||
- name: Black
|
|
||||||
run: black --check --diff --no-color --quiet .
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: pytest -x -v --durations=30 tests
|
run: pytest -m "not slow" -x -v --durations=30 tests
|
||||||
|
pydantic1x:
|
||||||
|
timeout-minutes: 30
|
||||||
|
runs-on: "ubuntu-22.04"
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: bash
|
||||||
|
working-directory: python
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
lfs: true
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: 3.9
|
||||||
|
- name: Install lancedb
|
||||||
|
run: |
|
||||||
|
pip install "pydantic<2"
|
||||||
|
pip install -e .[tests]
|
||||||
|
pip install tantivy@git+https://github.com/quickwit-oss/tantivy-py#164adc87e1a033117001cf70e38c82a53014d985
|
||||||
|
pip install pytest pytest-mock
|
||||||
|
- name: Run tests
|
||||||
|
run: pytest -m "not slow" -x -v --durations=30 tests
|
||||||
|
- name: doctest
|
||||||
|
run: pytest --doctest-modules lancedb
|
||||||
|
|||||||
40
.github/workflows/rust.yml
vendored
@@ -10,6 +10,10 @@ on:
|
|||||||
- rust/**
|
- rust/**
|
||||||
- .github/workflows/rust.yml
|
- .github/workflows/rust.yml
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
env:
|
env:
|
||||||
# This env var is used by Swatinem/rust-cache@v2 for the cache
|
# This env var is used by Swatinem/rust-cache@v2 for the cache
|
||||||
# key, so we set it to make sure it is always consistent.
|
# key, so we set it to make sure it is always consistent.
|
||||||
@@ -20,6 +24,29 @@ env:
|
|||||||
RUST_BACKTRACE: "1"
|
RUST_BACKTRACE: "1"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
lint:
|
||||||
|
timeout-minutes: 30
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: bash
|
||||||
|
working-directory: rust
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
lfs: true
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
with:
|
||||||
|
workspaces: rust
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install -y protobuf-compiler libssl-dev
|
||||||
|
- name: Run format
|
||||||
|
run: cargo fmt --all -- --check
|
||||||
|
- name: Run clippy
|
||||||
|
run: cargo clippy --all --all-features -- -D warnings
|
||||||
linux:
|
linux:
|
||||||
timeout-minutes: 30
|
timeout-minutes: 30
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
@@ -28,7 +55,7 @@ jobs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
working-directory: rust
|
working-directory: rust
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
lfs: true
|
lfs: true
|
||||||
@@ -43,15 +70,20 @@ jobs:
|
|||||||
run: cargo build --all-features
|
run: cargo build --all-features
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: cargo test --all-features
|
run: cargo test --all-features
|
||||||
|
- name: Run examples
|
||||||
|
run: cargo run --example simple
|
||||||
macos:
|
macos:
|
||||||
runs-on: macos-12
|
|
||||||
timeout-minutes: 30
|
timeout-minutes: 30
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
mac-runner: [ "macos-13", "macos-14" ]
|
||||||
|
runs-on: "${{ matrix.mac-runner }}"
|
||||||
defaults:
|
defaults:
|
||||||
run:
|
run:
|
||||||
shell: bash
|
shell: bash
|
||||||
working-directory: rust
|
working-directory: rust
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
lfs: true
|
lfs: true
|
||||||
@@ -69,7 +101,7 @@ jobs:
|
|||||||
windows:
|
windows:
|
||||||
runs-on: windows-2022
|
runs-on: windows-2022
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
with:
|
with:
|
||||||
workspaces: rust
|
workspaces: rust
|
||||||
|
|||||||
26
.github/workflows/trigger-vectordb-recipes.yml
vendored
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
name: Trigger vectordb-recipers workflow
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ main ]
|
||||||
|
pull_request:
|
||||||
|
paths:
|
||||||
|
- .github/workflows/trigger-vectordb-recipes.yml
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Trigger vectordb-recipes workflow
|
||||||
|
uses: actions/github-script@v6
|
||||||
|
with:
|
||||||
|
github-token: ${{ secrets.VECTORDB_RECIPES_ACTION_TOKEN }}
|
||||||
|
script: |
|
||||||
|
const result = await github.rest.actions.createWorkflowDispatch({
|
||||||
|
owner: 'lancedb',
|
||||||
|
repo: 'vectordb-recipes',
|
||||||
|
workflow_id: 'examples-test.yml',
|
||||||
|
ref: 'main'
|
||||||
|
});
|
||||||
|
console.log(result);
|
||||||
13
.github/workflows/update_package_lock/action.yml
vendored
@@ -1,6 +1,11 @@
|
|||||||
name: update_package_lock
|
name: update_package_lock
|
||||||
description: "Update node's package.lock"
|
description: "Update node's package.lock"
|
||||||
|
|
||||||
|
inputs:
|
||||||
|
github_token:
|
||||||
|
required: true
|
||||||
|
description: "github token for the repo"
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: "composite"
|
using: "composite"
|
||||||
steps:
|
steps:
|
||||||
@@ -18,5 +23,11 @@ runs:
|
|||||||
npm install
|
npm install
|
||||||
git add package-lock.json
|
git add package-lock.json
|
||||||
git commit -m "Updating package-lock.json"
|
git commit -m "Updating package-lock.json"
|
||||||
git push
|
|
||||||
shell: bash
|
shell: bash
|
||||||
|
- name: Push changes
|
||||||
|
if: ${{ inputs.dry_run }} == "false"
|
||||||
|
uses: ad-m/github-push-action@master
|
||||||
|
with:
|
||||||
|
github_token: ${{ inputs.github_token }}
|
||||||
|
branch: main
|
||||||
|
tags: true
|
||||||
|
|||||||
@@ -8,5 +8,12 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: main
|
||||||
|
persist-credentials: false
|
||||||
|
fetch-depth: 0
|
||||||
|
lfs: true
|
||||||
- uses: ./.github/workflows/update_package_lock
|
- uses: ./.github/workflows/update_package_lock
|
||||||
|
with:
|
||||||
|
github_token: ${{ secrets.LANCEDB_RELEASE_TOKEN }}
|
||||||
|
|||||||
3
.gitignore
vendored
@@ -29,8 +29,9 @@ python/dist
|
|||||||
node/dist
|
node/dist
|
||||||
node/examples/**/package-lock.json
|
node/examples/**/package-lock.json
|
||||||
node/examples/**/dist
|
node/examples/**/dist
|
||||||
|
dist
|
||||||
|
|
||||||
## Rust
|
## Rust
|
||||||
target
|
target
|
||||||
|
|
||||||
Cargo.lock
|
Cargo.lock
|
||||||
|
|||||||
48
Cargo.toml
@@ -1,16 +1,40 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = ["rust/ffi/node", "rust/vectordb", "nodejs"]
|
||||||
"rust/vectordb",
|
# Python package needs to be built by maturin.
|
||||||
"rust/ffi/node"
|
exclude = ["python"]
|
||||||
]
|
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.package]
|
||||||
lance = "=0.5.8"
|
edition = "2021"
|
||||||
arrow-array = "42.0"
|
authors = ["LanceDB Devs <dev@lancedb.com>"]
|
||||||
arrow-data = "42.0"
|
license = "Apache-2.0"
|
||||||
arrow-schema = "42.0"
|
repository = "https://github.com/lancedb/lancedb"
|
||||||
arrow-ipc = "42.0"
|
description = "Serverless, low-latency vector database for AI applications"
|
||||||
half = { "version" = "=2.2.1", default-features = false }
|
keywords = ["lancedb", "lance", "database", "vector", "search"]
|
||||||
object_store = "0.6.1"
|
categories = ["database-implementations"]
|
||||||
|
|
||||||
|
[workspace.dependencies]
|
||||||
|
lance = { "version" = "=0.9.16", "features" = ["dynamodb"] }
|
||||||
|
lance-index = { "version" = "=0.9.16" }
|
||||||
|
lance-linalg = { "version" = "=0.9.16" }
|
||||||
|
lance-testing = { "version" = "=0.9.16" }
|
||||||
|
# Note that this one does not include pyarrow
|
||||||
|
arrow = { version = "50.0", optional = false }
|
||||||
|
arrow-array = "50.0"
|
||||||
|
arrow-data = "50.0"
|
||||||
|
arrow-ipc = "50.0"
|
||||||
|
arrow-ord = "50.0"
|
||||||
|
arrow-schema = "50.0"
|
||||||
|
arrow-arith = "50.0"
|
||||||
|
arrow-cast = "50.0"
|
||||||
|
async-trait = "0"
|
||||||
|
chrono = "0.4.23"
|
||||||
|
half = { "version" = "=2.3.1", default-features = false, features = [
|
||||||
|
"num-traits",
|
||||||
|
] }
|
||||||
|
futures = "0"
|
||||||
|
log = "0.4"
|
||||||
|
object_store = "0.9.0"
|
||||||
|
snafu = "0.7.4"
|
||||||
|
url = "2"
|
||||||
|
num-traits = "0.2"
|
||||||
|
|||||||
165
README.md
@@ -1,78 +1,87 @@
|
|||||||
<div align="center">
|
<div align="center">
|
||||||
<p align="center">
|
<p align="center">
|
||||||
|
|
||||||
<img width="275" alt="LanceDB Logo" src="https://user-images.githubusercontent.com/917119/226205734-6063d87a-1ecc-45fe-85be-1dea6383a3d8.png">
|
<img width="275" alt="LanceDB Logo" src="https://user-images.githubusercontent.com/917119/226205734-6063d87a-1ecc-45fe-85be-1dea6383a3d8.png">
|
||||||
|
|
||||||
**Developer-friendly, serverless vector database for AI applications**
|
**Developer-friendly, serverless vector database for AI applications**
|
||||||
|
|
||||||
<a href="https://lancedb.github.io/lancedb/">Documentation</a> •
|
<a href='https://github.com/lancedb/vectordb-recipes/tree/main' target="_blank"><img alt='LanceDB' src='https://img.shields.io/badge/VectorDB_Recipes-100000?style=for-the-badge&logo=LanceDB&logoColor=white&labelColor=645cfb&color=645cfb'/></a>
|
||||||
<a href="https://blog.lancedb.com/">Blog</a> •
|
<a href='https://lancedb.github.io/lancedb/' target="_blank"><img alt='lancdb' src='https://img.shields.io/badge/DOCS-100000?style=for-the-badge&logo=lancdb&logoColor=white&labelColor=645cfb&color=645cfb'/></a>
|
||||||
<a href="https://discord.gg/zMM32dvNtd">Discord</a> •
|
[](https://blog.lancedb.com/)
|
||||||
<a href="https://twitter.com/lancedb">Twitter</a>
|
[](https://discord.gg/zMM32dvNtd)
|
||||||
|
[](https://twitter.com/lancedb)
|
||||||
</p>
|
|
||||||
|
</p>
|
||||||
<img max-width="750px" alt="LanceDB Multimodal Search" src="https://github.com/lancedb/lancedb/assets/917119/09c5afc5-7816-4687-bae4-f2ca194426ec">
|
|
||||||
|
<img max-width="750px" alt="LanceDB Multimodal Search" src="https://github.com/lancedb/lancedb/assets/917119/09c5afc5-7816-4687-bae4-f2ca194426ec">
|
||||||
</p>
|
|
||||||
</div>
|
</p>
|
||||||
|
</div>
|
||||||
<hr />
|
|
||||||
|
<hr />
|
||||||
LanceDB is an open-source database for vector-search built with persistent storage, which greatly simplifies retrevial, filtering and management of embeddings.
|
|
||||||
|
LanceDB is an open-source database for vector-search built with persistent storage, which greatly simplifies retrevial, filtering and management of embeddings.
|
||||||
The key features of LanceDB include:
|
|
||||||
|
The key features of LanceDB include:
|
||||||
* Production-scale vector search with no servers to manage.
|
|
||||||
|
* Production-scale vector search with no servers to manage.
|
||||||
* Store, query and filter vectors, metadata and multi-modal data (text, images, videos, point clouds, and more).
|
|
||||||
|
* Store, query and filter vectors, metadata and multi-modal data (text, images, videos, point clouds, and more).
|
||||||
* Support for vector similarity search, full-text search and SQL.
|
|
||||||
|
* Support for vector similarity search, full-text search and SQL.
|
||||||
* Native Python and Javascript/Typescript support.
|
|
||||||
|
* Native Python and Javascript/Typescript support.
|
||||||
* Zero-copy, automatic versioning, manage versions of your data without needing extra infrastructure.
|
|
||||||
|
* Zero-copy, automatic versioning, manage versions of your data without needing extra infrastructure.
|
||||||
* Ecosystem integrations with [LangChain 🦜️🔗](https://python.langchain.com/en/latest/modules/indexes/vectorstores/examples/lanecdb.html), [LlamaIndex 🦙](https://gpt-index.readthedocs.io/en/latest/examples/vector_stores/LanceDBIndexDemo.html), Apache-Arrow, Pandas, Polars, DuckDB and more on the way.
|
|
||||||
|
* GPU support in building vector index(*).
|
||||||
LanceDB's core is written in Rust 🦀 and is built using <a href="https://github.com/lancedb/lance">Lance</a>, an open-source columnar format designed for performant ML workloads.
|
|
||||||
|
* Ecosystem integrations with [LangChain 🦜️🔗](https://python.langchain.com/en/latest/modules/indexes/vectorstores/examples/lanecdb.html), [LlamaIndex 🦙](https://gpt-index.readthedocs.io/en/latest/examples/vector_stores/LanceDBIndexDemo.html), Apache-Arrow, Pandas, Polars, DuckDB and more on the way.
|
||||||
## Quick Start
|
|
||||||
|
LanceDB's core is written in Rust 🦀 and is built using <a href="https://github.com/lancedb/lance">Lance</a>, an open-source columnar format designed for performant ML workloads.
|
||||||
**Javascript**
|
|
||||||
```shell
|
## Quick Start
|
||||||
npm install vectordb
|
|
||||||
```
|
**Javascript**
|
||||||
|
```shell
|
||||||
```javascript
|
npm install vectordb
|
||||||
const lancedb = require('vectordb');
|
```
|
||||||
const db = await lancedb.connect('data/sample-lancedb');
|
|
||||||
|
```javascript
|
||||||
const table = await db.createTable('vectors',
|
const lancedb = require('vectordb');
|
||||||
[{ id: 1, vector: [0.1, 0.2], item: "foo", price: 10 },
|
const db = await lancedb.connect('data/sample-lancedb');
|
||||||
{ id: 2, vector: [1.1, 1.2], item: "bar", price: 50 }])
|
|
||||||
|
const table = await db.createTable({
|
||||||
const query = table.search([0.1, 0.3]);
|
name: 'vectors',
|
||||||
query.limit = 20;
|
data: [
|
||||||
const results = await query.execute();
|
{ id: 1, vector: [0.1, 0.2], item: "foo", price: 10 },
|
||||||
```
|
{ id: 2, vector: [1.1, 1.2], item: "bar", price: 50 }
|
||||||
|
]
|
||||||
**Python**
|
})
|
||||||
```shell
|
|
||||||
pip install lancedb
|
const query = table.search([0.1, 0.3]).limit(2);
|
||||||
```
|
const results = await query.execute();
|
||||||
|
|
||||||
```python
|
// You can also search for rows by specific criteria without involving a vector search.
|
||||||
import lancedb
|
const rowsByCriteria = await table.search(undefined).where("price >= 10").execute();
|
||||||
|
```
|
||||||
uri = "data/sample-lancedb"
|
|
||||||
db = lancedb.connect(uri)
|
**Python**
|
||||||
table = db.create_table("my_table",
|
```shell
|
||||||
data=[{"vector": [3.1, 4.1], "item": "foo", "price": 10.0},
|
pip install lancedb
|
||||||
{"vector": [5.9, 26.5], "item": "bar", "price": 20.0}])
|
```
|
||||||
result = table.search([100, 100]).limit(2).to_df()
|
|
||||||
```
|
```python
|
||||||
|
import lancedb
|
||||||
## Blogs, Tutorials & Videos
|
|
||||||
* 📈 <a href="https://blog.eto.ai/benchmarking-random-access-in-lance-ed690757a826">2000x better performance with Lance over Parquet</a>
|
uri = "data/sample-lancedb"
|
||||||
* 🤖 <a href="https://github.com/lancedb/lancedb/blob/main/docs/src/notebooks/youtube_transcript_search.ipynb">Build a question and answer bot with LanceDB</a>
|
db = lancedb.connect(uri)
|
||||||
|
table = db.create_table("my_table",
|
||||||
|
data=[{"vector": [3.1, 4.1], "item": "foo", "price": 10.0},
|
||||||
|
{"vector": [5.9, 26.5], "item": "bar", "price": 20.0}])
|
||||||
|
result = table.search([100, 100]).limit(2).to_pandas()
|
||||||
|
```
|
||||||
|
|
||||||
|
## Blogs, Tutorials & Videos
|
||||||
|
* 📈 <a href="https://blog.eto.ai/benchmarking-random-access-in-lance-ed690757a826">2000x better performance with Lance over Parquet</a>
|
||||||
|
* 🤖 <a href="https://github.com/lancedb/lancedb/blob/main/docs/src/notebooks/youtube_transcript_search.ipynb">Build a question and answer bot with LanceDB</a>
|
||||||
|
|||||||
85
ci/build_linux_artifacts.sh
Normal file → Executable file
@@ -1,72 +1,21 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Builds the Linux artifacts (node binaries).
|
|
||||||
# Usage: ./build_linux_artifacts.sh [target]
|
|
||||||
# Targets supported:
|
|
||||||
# - x86_64-unknown-linux-gnu:centos
|
|
||||||
# - aarch64-unknown-linux-gnu:centos
|
|
||||||
# - aarch64-unknown-linux-musl
|
|
||||||
# - x86_64-unknown-linux-musl
|
|
||||||
|
|
||||||
# TODO: refactor this into a Docker container we can pull
|
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
ARCH=${1:-x86_64}
|
||||||
|
|
||||||
setup_dependencies() {
|
# We pass down the current user so that when we later mount the local files
|
||||||
echo "Installing system dependencies..."
|
# into the container, the files are accessible by the current user.
|
||||||
if [[ $1 == *musl ]]; then
|
pushd ci/manylinux_node
|
||||||
# musllinux
|
docker build \
|
||||||
apk add openssl-dev
|
-t lancedb-node-manylinux \
|
||||||
else
|
--build-arg="ARCH=$ARCH" \
|
||||||
# rust / debian
|
--build-arg="DOCKER_USER=$(id -u)" \
|
||||||
apt update
|
--progress=plain \
|
||||||
apt install -y libssl-dev protobuf-compiler
|
.
|
||||||
fi
|
popd
|
||||||
}
|
|
||||||
|
|
||||||
install_node() {
|
# We turn on memory swap to avoid OOM killer
|
||||||
echo "Installing node..."
|
docker run \
|
||||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
|
-v $(pwd):/io -w /io \
|
||||||
source "$HOME"/.bashrc
|
--memory-swap=-1 \
|
||||||
|
lancedb-node-manylinux \
|
||||||
if [[ $1 == *musl ]]; then
|
bash ci/manylinux_node/build.sh $ARCH
|
||||||
# This node version is 15, we need 16 or higher:
|
|
||||||
# apk add nodejs-current npm
|
|
||||||
# So instead we install from source (nvm doesn't provide binaries for musl):
|
|
||||||
nvm install -s --no-progress 17
|
|
||||||
else
|
|
||||||
nvm install --no-progress 17 # latest that supports glibc 2.17
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
build_node_binary() {
|
|
||||||
echo "Building node library for $1..."
|
|
||||||
pushd node
|
|
||||||
|
|
||||||
npm ci
|
|
||||||
|
|
||||||
if [[ $1 == *musl ]]; then
|
|
||||||
# This is needed for cargo to allow build cdylibs with musl
|
|
||||||
export RUSTFLAGS="-C target-feature=-crt-static"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Cargo can run out of memory while pulling dependencies, especially when running
|
|
||||||
# in QEMU. This is a workaround for that.
|
|
||||||
export CARGO_NET_GIT_FETCH_WITH_CLI=true
|
|
||||||
|
|
||||||
# We don't pass in target, since the native target here already matches
|
|
||||||
# We need to pass OPENSSL_LIB_DIR and OPENSSL_INCLUDE_DIR for static build to work https://github.com/sfackler/rust-openssl/issues/877
|
|
||||||
OPENSSL_STATIC=1 OPENSSL_LIB_DIR=/usr/lib/x86_64-linux-gnu OPENSSL_INCLUDE_DIR=/usr/include/openssl/ npm run build-release
|
|
||||||
npm run pack-build
|
|
||||||
|
|
||||||
popd
|
|
||||||
}
|
|
||||||
|
|
||||||
TARGET=${1:-x86_64-unknown-linux-gnu}
|
|
||||||
# Others:
|
|
||||||
# aarch64-unknown-linux-gnu
|
|
||||||
# x86_64-unknown-linux-musl
|
|
||||||
# aarch64-unknown-linux-musl
|
|
||||||
|
|
||||||
setup_dependencies $TARGET
|
|
||||||
install_node $TARGET
|
|
||||||
build_node_binary $TARGET
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# Builds the macOS artifacts (node binaries).
|
# Builds the macOS artifacts (node binaries).
|
||||||
# Usage: ./ci/build_macos_artifacts.sh [target]
|
# Usage: ./ci/build_macos_artifacts.sh [target]
|
||||||
# Targets supported: x86_64-apple-darwin aarch64-apple-darwin
|
# Targets supported: x86_64-apple-darwin aarch64-apple-darwin
|
||||||
|
set -e
|
||||||
|
|
||||||
prebuild_rust() {
|
prebuild_rust() {
|
||||||
# Building here for the sake of easier debugging.
|
# Building here for the sake of easier debugging.
|
||||||
|
|||||||
31
ci/manylinux_node/Dockerfile
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
# Many linux dockerfile with Rust, Node, and Lance dependencies installed.
|
||||||
|
# This container allows building the node modules native libraries in an
|
||||||
|
# environment with a very old glibc, so that we are compatible with a wide
|
||||||
|
# range of linux distributions.
|
||||||
|
ARG ARCH=x86_64
|
||||||
|
|
||||||
|
FROM quay.io/pypa/manylinux2014_${ARCH}
|
||||||
|
|
||||||
|
ARG ARCH=x86_64
|
||||||
|
ARG DOCKER_USER=default_user
|
||||||
|
|
||||||
|
# Install static openssl
|
||||||
|
COPY install_openssl.sh install_openssl.sh
|
||||||
|
RUN ./install_openssl.sh ${ARCH} > /dev/null
|
||||||
|
|
||||||
|
# Protobuf is also installed as root.
|
||||||
|
COPY install_protobuf.sh install_protobuf.sh
|
||||||
|
RUN ./install_protobuf.sh ${ARCH}
|
||||||
|
|
||||||
|
ENV DOCKER_USER=${DOCKER_USER}
|
||||||
|
# Create a group and user
|
||||||
|
RUN echo ${ARCH} && adduser --user-group --create-home --uid ${DOCKER_USER} build_user
|
||||||
|
|
||||||
|
# We switch to the user to install Rust and Node, since those like to be
|
||||||
|
# installed at the user level.
|
||||||
|
USER ${DOCKER_USER}
|
||||||
|
|
||||||
|
COPY prepare_manylinux_node.sh prepare_manylinux_node.sh
|
||||||
|
RUN cp /prepare_manylinux_node.sh $HOME/ && \
|
||||||
|
cd $HOME && \
|
||||||
|
./prepare_manylinux_node.sh ${ARCH}
|
||||||
19
ci/manylinux_node/build.sh
Executable file
@@ -0,0 +1,19 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Builds the node module for manylinux. Invoked by ci/build_linux_artifacts.sh.
|
||||||
|
set -e
|
||||||
|
ARCH=${1:-x86_64}
|
||||||
|
|
||||||
|
if [ "$ARCH" = "x86_64" ]; then
|
||||||
|
export OPENSSL_LIB_DIR=/usr/local/lib64/
|
||||||
|
else
|
||||||
|
export OPENSSL_LIB_DIR=/usr/local/lib/
|
||||||
|
fi
|
||||||
|
export OPENSSL_STATIC=1
|
||||||
|
export OPENSSL_INCLUDE_DIR=/usr/local/include/openssl
|
||||||
|
|
||||||
|
source $HOME/.bashrc
|
||||||
|
|
||||||
|
cd node
|
||||||
|
npm ci
|
||||||
|
npm run build-release
|
||||||
|
npm run pack-build
|
||||||
26
ci/manylinux_node/install_openssl.sh
Executable file
@@ -0,0 +1,26 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Builds openssl from source so we can statically link to it
|
||||||
|
|
||||||
|
# this is to avoid the error we get with the system installation:
|
||||||
|
# /usr/bin/ld: <library>: version node not found for symbol SSLeay@@OPENSSL_1.0.1
|
||||||
|
# /usr/bin/ld: failed to set dynamic section sizes: Bad value
|
||||||
|
set -e
|
||||||
|
|
||||||
|
git clone -b OpenSSL_1_1_1u \
|
||||||
|
--single-branch \
|
||||||
|
https://github.com/openssl/openssl.git
|
||||||
|
|
||||||
|
pushd openssl
|
||||||
|
|
||||||
|
if [[ $1 == x86_64* ]]; then
|
||||||
|
ARCH=linux-x86_64
|
||||||
|
else
|
||||||
|
# gnu target
|
||||||
|
ARCH=linux-aarch64
|
||||||
|
fi
|
||||||
|
|
||||||
|
./Configure no-shared $ARCH
|
||||||
|
|
||||||
|
make
|
||||||
|
|
||||||
|
make install
|
||||||
15
ci/manylinux_node/install_protobuf.sh
Executable file
@@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Installs protobuf compiler. Should be run as root.
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [[ $1 == x86_64* ]]; then
|
||||||
|
ARCH=x86_64
|
||||||
|
else
|
||||||
|
# gnu target
|
||||||
|
ARCH=aarch_64
|
||||||
|
fi
|
||||||
|
|
||||||
|
PB_REL=https://github.com/protocolbuffers/protobuf/releases
|
||||||
|
PB_VERSION=23.1
|
||||||
|
curl -LO $PB_REL/download/v$PB_VERSION/protoc-$PB_VERSION-linux-$ARCH.zip
|
||||||
|
unzip protoc-$PB_VERSION-linux-$ARCH.zip -d /usr/local
|
||||||
21
ci/manylinux_node/prepare_manylinux_node.sh
Executable file
@@ -0,0 +1,21 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
install_node() {
|
||||||
|
echo "Installing node..."
|
||||||
|
|
||||||
|
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
|
||||||
|
|
||||||
|
source "$HOME"/.bashrc
|
||||||
|
|
||||||
|
nvm install --no-progress 16
|
||||||
|
}
|
||||||
|
|
||||||
|
install_rust() {
|
||||||
|
echo "Installing rust..."
|
||||||
|
curl https://sh.rustup.rs -sSf | bash -s -- -y
|
||||||
|
export PATH="$PATH:/root/.cargo/bin"
|
||||||
|
}
|
||||||
|
|
||||||
|
install_node
|
||||||
|
install_rust
|
||||||
18
docker-compose.yml
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
version: "3.9"
|
||||||
|
services:
|
||||||
|
localstack:
|
||||||
|
image: localstack/localstack:0.14
|
||||||
|
ports:
|
||||||
|
- 4566:4566
|
||||||
|
environment:
|
||||||
|
- SERVICES=s3,dynamodb
|
||||||
|
- DEBUG=1
|
||||||
|
- LS_LOG=trace
|
||||||
|
- DOCKER_HOST=unix:///var/run/docker.sock
|
||||||
|
- AWS_ACCESS_KEY_ID=ACCESSKEY
|
||||||
|
- AWS_SECRET_ACCESS_KEY=SECRETKEY
|
||||||
|
healthcheck:
|
||||||
|
test: [ "CMD", "curl", "-f", "http://localhost:4566/health" ]
|
||||||
|
interval: 5s
|
||||||
|
retries: 3
|
||||||
|
start_period: 10s
|
||||||
44
docs/README.md
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
# LanceDB Documentation
|
||||||
|
|
||||||
|
LanceDB docs are deployed to https://lancedb.github.io/lancedb/.
|
||||||
|
|
||||||
|
Docs is built and deployed automatically by [Github Actions](.github/workflows/docs.yml)
|
||||||
|
whenever a commit is pushed to the `main` branch. So it is possible for the docs to show
|
||||||
|
unreleased features.
|
||||||
|
|
||||||
|
## Building the docs
|
||||||
|
|
||||||
|
### Setup
|
||||||
|
1. Install LanceDB. From LanceDB repo root: `pip install -e python`
|
||||||
|
2. Install dependencies. From LanceDB repo root: `pip install -r docs/requirements.txt`
|
||||||
|
3. Make sure you have node and npm setup
|
||||||
|
4. Make sure protobuf and libssl are installed
|
||||||
|
|
||||||
|
### Building node module and create markdown files
|
||||||
|
|
||||||
|
See [Javascript docs README](./src/javascript/README.md)
|
||||||
|
|
||||||
|
### Build docs
|
||||||
|
From LanceDB repo root:
|
||||||
|
|
||||||
|
Run: `PYTHONPATH=. mkdocs build -f docs/mkdocs.yml`
|
||||||
|
|
||||||
|
If successful, you should see a `docs/site` directory that you can verify locally.
|
||||||
|
|
||||||
|
### Run local server
|
||||||
|
|
||||||
|
You can run a local server to test the docs prior to deployment by navigating to the `docs` directory and running the following command:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd docs
|
||||||
|
mkdocs serve
|
||||||
|
```
|
||||||
|
|
||||||
|
### Run doctest for typescript example
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd lancedb/docs
|
||||||
|
npm i
|
||||||
|
npm run build
|
||||||
|
npm run all
|
||||||
|
```
|
||||||
177
docs/mkdocs.yml
@@ -1,5 +1,7 @@
|
|||||||
site_name: LanceDB Docs
|
site_name: LanceDB
|
||||||
|
site_url: https://lancedb.github.io/lancedb/
|
||||||
repo_url: https://github.com/lancedb/lancedb
|
repo_url: https://github.com/lancedb/lancedb
|
||||||
|
edit_uri: https://github.com/lancedb/lancedb/tree/main/docs/src
|
||||||
repo_name: lancedb/lancedb
|
repo_name: lancedb/lancedb
|
||||||
docs_dir: src
|
docs_dir: src
|
||||||
|
|
||||||
@@ -7,9 +9,31 @@ theme:
|
|||||||
name: "material"
|
name: "material"
|
||||||
logo: assets/logo.png
|
logo: assets/logo.png
|
||||||
favicon: assets/logo.png
|
favicon: assets/logo.png
|
||||||
|
palette:
|
||||||
|
# Palette toggle for light mode
|
||||||
|
- scheme: lancedb
|
||||||
|
primary: custom
|
||||||
|
toggle:
|
||||||
|
icon: material/weather-night
|
||||||
|
name: Switch to dark mode
|
||||||
|
# Palette toggle for dark mode
|
||||||
|
- scheme: slate
|
||||||
|
primary: custom
|
||||||
|
toggle:
|
||||||
|
icon: material/weather-sunny
|
||||||
|
name: Switch to light mode
|
||||||
features:
|
features:
|
||||||
- content.code.copy
|
- content.code.copy
|
||||||
- content.tabs.link
|
- content.tabs.link
|
||||||
|
- content.action.edit
|
||||||
|
- toc.follow
|
||||||
|
# - toc.integrate
|
||||||
|
- navigation.top
|
||||||
|
- navigation.tabs
|
||||||
|
- navigation.tabs.sticky
|
||||||
|
- navigation.footer
|
||||||
|
- navigation.tracking
|
||||||
|
- navigation.instant
|
||||||
icon:
|
icon:
|
||||||
repo: fontawesome/brands/github
|
repo: fontawesome/brands/github
|
||||||
custom_dir: overrides
|
custom_dir: overrides
|
||||||
@@ -21,14 +45,12 @@ plugins:
|
|||||||
handlers:
|
handlers:
|
||||||
python:
|
python:
|
||||||
paths: [../python]
|
paths: [../python]
|
||||||
selection:
|
options:
|
||||||
docstring_style: numpy
|
docstring_style: numpy
|
||||||
rendering:
|
|
||||||
heading_level: 4
|
heading_level: 4
|
||||||
show_source: false
|
show_source: true
|
||||||
show_symbol_type_in_heading: true
|
show_symbol_type_in_heading: true
|
||||||
show_signature_annotations: true
|
show_signature_annotations: true
|
||||||
show_root_heading: true
|
|
||||||
members_order: source
|
members_order: source
|
||||||
import:
|
import:
|
||||||
# for cross references
|
# for cross references
|
||||||
@@ -39,46 +61,155 @@ plugins:
|
|||||||
markdown_extensions:
|
markdown_extensions:
|
||||||
- admonition
|
- admonition
|
||||||
- footnotes
|
- footnotes
|
||||||
- pymdownx.superfences
|
|
||||||
- pymdownx.details
|
- pymdownx.details
|
||||||
- pymdownx.highlight:
|
- pymdownx.highlight:
|
||||||
anchor_linenums: true
|
anchor_linenums: true
|
||||||
line_spans: __span
|
line_spans: __span
|
||||||
pygments_lang_class: true
|
pygments_lang_class: true
|
||||||
- pymdownx.inlinehilite
|
- pymdownx.inlinehilite
|
||||||
- pymdownx.snippets
|
- pymdownx.snippets:
|
||||||
|
base_path: ..
|
||||||
|
dedent_subsections: true
|
||||||
- pymdownx.superfences
|
- pymdownx.superfences
|
||||||
- pymdownx.tabbed:
|
- pymdownx.tabbed:
|
||||||
alternate_style: true
|
alternate_style: true
|
||||||
- md_in_html
|
- md_in_html
|
||||||
|
- attr_list
|
||||||
|
|
||||||
nav:
|
nav:
|
||||||
- Home: index.md
|
- Home:
|
||||||
- Basics: basic.md
|
- LanceDB: index.md
|
||||||
- Embeddings: embedding.md
|
- 🏃🏼♂️ Quick start: basic.md
|
||||||
- Python full-text search: fts.md
|
- 📚 Concepts:
|
||||||
- Python integrations:
|
- Vector search: concepts/vector_search.md
|
||||||
- Pandas and PyArrow: python/arrow.md
|
- Indexing: concepts/index_ivfpq.md
|
||||||
- DuckDB: python/duckdb.md
|
- Storage: concepts/storage.md
|
||||||
- LangChain 🦜️🔗: https://python.langchain.com/en/latest/modules/indexes/vectorstores/examples/lancedb.html
|
- Data management: concepts/data_management.md
|
||||||
- LlamaIndex 🦙: https://gpt-index.readthedocs.io/en/latest/examples/vector_stores/LanceDBIndexDemo.html
|
- 🔨 Guides:
|
||||||
|
- Working with tables: guides/tables.md
|
||||||
|
- Building an ANN index: ann_indexes.md
|
||||||
|
- Vector Search: search.md
|
||||||
|
- Full-text search: fts.md
|
||||||
|
- Hybrid search:
|
||||||
|
- Overview: hybrid_search/hybrid_search.md
|
||||||
|
- Comparing Rerankers: hybrid_search/eval.md
|
||||||
|
- Airbnb financial data example: notebooks/hybrid_search.ipynb
|
||||||
|
- Filtering: sql.md
|
||||||
|
- Versioning & Reproducibility: notebooks/reproducibility.ipynb
|
||||||
|
- Configuring Storage: guides/storage.md
|
||||||
|
- 🧬 Managing embeddings:
|
||||||
|
- Overview: embeddings/index.md
|
||||||
|
- Explicit management: embeddings/embedding_explicit.md
|
||||||
|
- Implicit management: embeddings/embedding_functions.md
|
||||||
|
- Available Functions: embeddings/default_embedding_functions.md
|
||||||
|
- Custom Embedding Functions: embeddings/api.md
|
||||||
|
- "Example: Multi-lingual semantic search": notebooks/multi_lingual_example.ipynb
|
||||||
|
- "Example: MultiModal CLIP Embeddings": notebooks/DisappearingEmbeddingFunction.ipynb
|
||||||
|
- 🔌 Integrations:
|
||||||
|
- Tools and data formats: integrations/index.md
|
||||||
|
- Pandas and PyArrow: python/pandas_and_pyarrow.md
|
||||||
|
- Polars: python/polars_arrow.md
|
||||||
|
- DuckDB: python/duckdb.md
|
||||||
|
- LangChain 🔗: https://python.langchain.com/en/latest/modules/indexes/vectorstores/examples/lancedb.html
|
||||||
|
- LangChain JS/TS 🔗: https://js.langchain.com/docs/modules/data_connection/vectorstores/integrations/lancedb
|
||||||
|
- LlamaIndex 🦙: https://gpt-index.readthedocs.io/en/latest/examples/vector_stores/LanceDBIndexDemo.html
|
||||||
|
- Pydantic: python/pydantic.md
|
||||||
|
- Voxel51: integrations/voxel51.md
|
||||||
|
- PromptTools: integrations/prompttools.md
|
||||||
|
- 🎯 Examples:
|
||||||
|
- Overview: examples/index.md
|
||||||
|
- 🐍 Python:
|
||||||
|
- Overview: examples/examples_python.md
|
||||||
|
- YouTube Transcript Search: notebooks/youtube_transcript_search.ipynb
|
||||||
|
- Documentation QA Bot using LangChain: notebooks/code_qa_bot.ipynb
|
||||||
|
- Multimodal search using CLIP: notebooks/multimodal_search.ipynb
|
||||||
|
- Example - Calculate CLIP Embeddings with Roboflow Inference: examples/image_embeddings_roboflow.md
|
||||||
|
- Serverless QA Bot with S3 and Lambda: examples/serverless_lancedb_with_s3_and_lambda.md
|
||||||
|
- Serverless QA Bot with Modal: examples/serverless_qa_bot_with_modal_and_langchain.md
|
||||||
|
- 👾 JavaScript:
|
||||||
|
- Overview: examples/examples_js.md
|
||||||
|
- Serverless Website Chatbot: examples/serverless_website_chatbot.md
|
||||||
|
- YouTube Transcript Search: examples/youtube_transcript_bot_with_nodejs.md
|
||||||
|
- TransformersJS Embedding Search: examples/transformerjs_embedding_search_nodejs.md
|
||||||
|
- 🔧 CLI & Config: cli_config.md
|
||||||
|
- 💭 FAQs: faq.md
|
||||||
|
- ⚙️ API reference:
|
||||||
|
- 🐍 Python: python/python.md
|
||||||
|
- 👾 JavaScript: javascript/modules.md
|
||||||
|
- 🦀 Rust: https://docs.rs/vectordb/latest/vectordb/
|
||||||
|
- ☁️ LanceDB Cloud:
|
||||||
|
- Overview: cloud/index.md
|
||||||
|
- API reference:
|
||||||
|
- 🐍 Python: python/saas-python.md
|
||||||
|
- 👾 JavaScript: javascript/saas-modules.md
|
||||||
|
|
||||||
|
|
||||||
|
- Quick start: basic.md
|
||||||
|
- Concepts:
|
||||||
|
- Vector search: concepts/vector_search.md
|
||||||
|
- Indexing: concepts/index_ivfpq.md
|
||||||
|
- Storage: concepts/storage.md
|
||||||
|
- Data management: concepts/data_management.md
|
||||||
|
- Guides:
|
||||||
|
- Working with tables: guides/tables.md
|
||||||
|
- Building an ANN index: ann_indexes.md
|
||||||
|
- Vector Search: search.md
|
||||||
|
- Full-text search: fts.md
|
||||||
|
- Hybrid search:
|
||||||
|
- Overview: hybrid_search/hybrid_search.md
|
||||||
|
- Comparing Rerankers: hybrid_search/eval.md
|
||||||
|
- Airbnb financial data example: notebooks/hybrid_search.ipynb
|
||||||
|
- Filtering: sql.md
|
||||||
|
- Versioning & Reproducibility: notebooks/reproducibility.ipynb
|
||||||
|
- Configuring Storage: guides/storage.md
|
||||||
|
- Managing Embeddings:
|
||||||
|
- Overview: embeddings/index.md
|
||||||
|
- Explicit management: embeddings/embedding_explicit.md
|
||||||
|
- Implicit management: embeddings/embedding_functions.md
|
||||||
|
- Available Functions: embeddings/default_embedding_functions.md
|
||||||
|
- Custom Embedding Functions: embeddings/api.md
|
||||||
|
- "Example: Multi-lingual semantic search": notebooks/multi_lingual_example.ipynb
|
||||||
|
- "Example: MultiModal CLIP Embeddings": notebooks/DisappearingEmbeddingFunction.ipynb
|
||||||
|
- Integrations:
|
||||||
|
- Overview: integrations/index.md
|
||||||
|
- Pandas and PyArrow: python/pandas_and_pyarrow.md
|
||||||
|
- Polars: python/polars_arrow.md
|
||||||
|
- DuckDB : python/duckdb.md
|
||||||
|
- LangChain 🦜️🔗↗: https://python.langchain.com/en/latest/modules/indexes/vectorstores/examples/lancedb.html
|
||||||
|
- LangChain.js 🦜️🔗↗: https://js.langchain.com/docs/modules/data_connection/vectorstores/integrations/lancedb
|
||||||
|
- LlamaIndex 🦙↗: https://gpt-index.readthedocs.io/en/latest/examples/vector_stores/LanceDBIndexDemo.html
|
||||||
- Pydantic: python/pydantic.md
|
- Pydantic: python/pydantic.md
|
||||||
|
- Voxel51: integrations/voxel51.md
|
||||||
|
- PromptTools: integrations/prompttools.md
|
||||||
- Python examples:
|
- Python examples:
|
||||||
|
- examples/index.md
|
||||||
- YouTube Transcript Search: notebooks/youtube_transcript_search.ipynb
|
- YouTube Transcript Search: notebooks/youtube_transcript_search.ipynb
|
||||||
- Documentation QA Bot using LangChain: notebooks/code_qa_bot.ipynb
|
- Documentation QA Bot using LangChain: notebooks/code_qa_bot.ipynb
|
||||||
- Multimodal search using CLIP: notebooks/multimodal_search.ipynb
|
- Multimodal search using CLIP: notebooks/multimodal_search.ipynb
|
||||||
- Serverless QA Bot with S3 and Lambda: examples/serverless_lancedb_with_s3_and_lambda.md
|
- Serverless QA Bot with S3 and Lambda: examples/serverless_lancedb_with_s3_and_lambda.md
|
||||||
- Serverless QA Bot with Modal: examples/serverless_qa_bot_with_modal_and_langchain.md
|
- Serverless QA Bot with Modal: examples/serverless_qa_bot_with_modal_and_langchain.md
|
||||||
- Javascript examples:
|
- Javascript examples:
|
||||||
|
- Overview: examples/examples_js.md
|
||||||
- YouTube Transcript Search: examples/youtube_transcript_bot_with_nodejs.md
|
- YouTube Transcript Search: examples/youtube_transcript_bot_with_nodejs.md
|
||||||
|
- Serverless Chatbot from any website: examples/serverless_website_chatbot.md
|
||||||
- TransformersJS Embedding Search: examples/transformerjs_embedding_search_nodejs.md
|
- TransformersJS Embedding Search: examples/transformerjs_embedding_search_nodejs.md
|
||||||
- References:
|
- API reference:
|
||||||
- Vector Search: search.md
|
- Python: python/python.md
|
||||||
- SQL filters: sql.md
|
- Javascript: javascript/modules.md
|
||||||
- Indexing: ann_indexes.md
|
- LanceDB Cloud:
|
||||||
- API references:
|
- Overview: cloud/index.md
|
||||||
- Python API: python/python.md
|
- API reference:
|
||||||
- Javascript API: javascript/modules.md
|
- 🐍 Python: python/saas-python.md
|
||||||
|
- 👾 JavaScript: javascript/saas-modules.md
|
||||||
|
|
||||||
extra_css:
|
extra_css:
|
||||||
- styles/global.css
|
- styles/global.css
|
||||||
|
- styles/extra.css
|
||||||
|
|
||||||
|
extra_javascript:
|
||||||
|
- "extra_js/init_ask_ai_widget.js"
|
||||||
|
|
||||||
|
extra:
|
||||||
|
analytics:
|
||||||
|
provider: google
|
||||||
|
property: G-B7NFM40W74
|
||||||
|
|||||||
132
docs/package-lock.json
generated
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
{
|
||||||
|
"name": "lancedb-docs-test",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"name": "lancedb-docs-test",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"license": "Apache 2",
|
||||||
|
"dependencies": {
|
||||||
|
"apache-arrow": "file:../node/node_modules/apache-arrow",
|
||||||
|
"vectordb": "file:../node"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/node": "^20.11.8",
|
||||||
|
"typescript": "^5.3.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"../node": {
|
||||||
|
"name": "vectordb",
|
||||||
|
"version": "0.4.6",
|
||||||
|
"cpu": [
|
||||||
|
"x64",
|
||||||
|
"arm64"
|
||||||
|
],
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"os": [
|
||||||
|
"darwin",
|
||||||
|
"linux",
|
||||||
|
"win32"
|
||||||
|
],
|
||||||
|
"dependencies": {
|
||||||
|
"@apache-arrow/ts": "^14.0.2",
|
||||||
|
"@neon-rs/load": "^0.0.74",
|
||||||
|
"apache-arrow": "^14.0.2",
|
||||||
|
"axios": "^1.4.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@neon-rs/cli": "^0.0.160",
|
||||||
|
"@types/chai": "^4.3.4",
|
||||||
|
"@types/chai-as-promised": "^7.1.5",
|
||||||
|
"@types/mocha": "^10.0.1",
|
||||||
|
"@types/node": "^18.16.2",
|
||||||
|
"@types/sinon": "^10.0.15",
|
||||||
|
"@types/temp": "^0.9.1",
|
||||||
|
"@types/uuid": "^9.0.3",
|
||||||
|
"@typescript-eslint/eslint-plugin": "^5.59.1",
|
||||||
|
"cargo-cp-artifact": "^0.1",
|
||||||
|
"chai": "^4.3.7",
|
||||||
|
"chai-as-promised": "^7.1.1",
|
||||||
|
"eslint": "^8.39.0",
|
||||||
|
"eslint-config-standard-with-typescript": "^34.0.1",
|
||||||
|
"eslint-plugin-import": "^2.26.0",
|
||||||
|
"eslint-plugin-n": "^15.7.0",
|
||||||
|
"eslint-plugin-promise": "^6.1.1",
|
||||||
|
"mocha": "^10.2.0",
|
||||||
|
"openai": "^4.24.1",
|
||||||
|
"sinon": "^15.1.0",
|
||||||
|
"temp": "^0.9.4",
|
||||||
|
"ts-node": "^10.9.1",
|
||||||
|
"ts-node-dev": "^2.0.0",
|
||||||
|
"typedoc": "^0.24.7",
|
||||||
|
"typedoc-plugin-markdown": "^3.15.3",
|
||||||
|
"typescript": "*",
|
||||||
|
"uuid": "^9.0.0"
|
||||||
|
},
|
||||||
|
"optionalDependencies": {
|
||||||
|
"@lancedb/vectordb-darwin-arm64": "0.4.6",
|
||||||
|
"@lancedb/vectordb-darwin-x64": "0.4.6",
|
||||||
|
"@lancedb/vectordb-linux-arm64-gnu": "0.4.6",
|
||||||
|
"@lancedb/vectordb-linux-x64-gnu": "0.4.6",
|
||||||
|
"@lancedb/vectordb-win32-x64-msvc": "0.4.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"../node/node_modules/apache-arrow": {
|
||||||
|
"version": "14.0.2",
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/command-line-args": "5.2.0",
|
||||||
|
"@types/command-line-usage": "5.0.2",
|
||||||
|
"@types/node": "20.3.0",
|
||||||
|
"@types/pad-left": "2.1.1",
|
||||||
|
"command-line-args": "5.2.1",
|
||||||
|
"command-line-usage": "7.0.1",
|
||||||
|
"flatbuffers": "23.5.26",
|
||||||
|
"json-bignum": "^0.0.3",
|
||||||
|
"pad-left": "^2.1.0",
|
||||||
|
"tslib": "^2.5.3"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"arrow2csv": "bin/arrow2csv.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@types/node": {
|
||||||
|
"version": "20.11.8",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.8.tgz",
|
||||||
|
"integrity": "sha512-i7omyekpPTNdv4Jb/Rgqg0RU8YqLcNsI12quKSDkRXNfx7Wxdm6HhK1awT3xTgEkgxPn3bvnSpiEAc7a7Lpyow==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"undici-types": "~5.26.4"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/apache-arrow": {
|
||||||
|
"resolved": "../node/node_modules/apache-arrow",
|
||||||
|
"link": true
|
||||||
|
},
|
||||||
|
"node_modules/typescript": {
|
||||||
|
"version": "5.3.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz",
|
||||||
|
"integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==",
|
||||||
|
"dev": true,
|
||||||
|
"bin": {
|
||||||
|
"tsc": "bin/tsc",
|
||||||
|
"tsserver": "bin/tsserver"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=14.17"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/undici-types": {
|
||||||
|
"version": "5.26.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz",
|
||||||
|
"integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"node_modules/vectordb": {
|
||||||
|
"resolved": "../node",
|
||||||
|
"link": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
20
docs/package.json
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"name": "lancedb-docs-test",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "auto-generated tests from doc",
|
||||||
|
"author": "dev@lancedb.com",
|
||||||
|
"license": "Apache 2",
|
||||||
|
"dependencies": {
|
||||||
|
"apache-arrow": "file:../node/node_modules/apache-arrow",
|
||||||
|
"vectordb": "file:../node"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"build": "tsc -b && cd ../node && npm run build-release",
|
||||||
|
"example": "npm run build && node",
|
||||||
|
"test": "npm run build && ls dist/*.js | xargs -n 1 node"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/node": "^20.11.8",
|
||||||
|
"typescript": "^5.3.3"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
mkdocs==1.4.2
|
mkdocs==1.5.3
|
||||||
mkdocs-jupyter==0.24.1
|
mkdocs-jupyter==0.24.1
|
||||||
mkdocs-material==9.1.3
|
mkdocs-material==9.5.3
|
||||||
mkdocstrings[python]==0.20.0
|
mkdocstrings[python]==0.20.0
|
||||||
|
pydantic
|
||||||
@@ -1,29 +1,33 @@
|
|||||||
# ANN (Approximate Nearest Neighbor) Indexes
|
# Approximate Nearest Neighbor (ANN) Indexes
|
||||||
|
|
||||||
You can create an index over your vector data to make search faster.
|
An ANN or a vector index is a data structure specifically designed to efficiently organize and
|
||||||
Vector indexes are faster but less accurate than exhaustive search (KNN or Flat Search).
|
search vector data based on their similarity via the chosen distance metric.
|
||||||
|
By constructing a vector index, the search space is effectively narrowed down, avoiding the need
|
||||||
|
for brute-force scanning of the entire vector space.
|
||||||
|
A vector index is faster but less accurate than exhaustive search (kNN or flat search).
|
||||||
LanceDB provides many parameters to fine-tune the index's size, the speed of queries, and the accuracy of results.
|
LanceDB provides many parameters to fine-tune the index's size, the speed of queries, and the accuracy of results.
|
||||||
|
|
||||||
Currently, LanceDB does *not* automatically create the ANN index.
|
Currently, LanceDB does _not_ automatically create the ANN index.
|
||||||
LanceDB has optimized code for KNN as well. For many use-cases, datasets under 100K vectors won't require index creation at all.
|
LanceDB has optimized code for kNN as well. For many use-cases, datasets under 100K vectors won't require index creation at all.
|
||||||
If you can live with <100ms latency, skipping index creation is a simpler workflow while guaranteeing 100% recall.
|
If you can live with <100ms latency, skipping index creation is a simpler workflow while guaranteeing 100% recall.
|
||||||
|
|
||||||
In the future we will look to automatically create and configure the ANN index.
|
In the future we will look to automatically create and configure the ANN index as data comes in.
|
||||||
|
|
||||||
## Types of Index
|
## Types of Index
|
||||||
|
|
||||||
Lance can support multiple index types, the most widely used one is `IVF_PQ`.
|
Lance can support multiple index types, the most widely used one is `IVF_PQ`.
|
||||||
|
|
||||||
* `IVF_PQ`: use **Inverted File Index (IVF)** to first divide the dataset into `N` partitions,
|
- `IVF_PQ`: use **Inverted File Index (IVF)** to first divide the dataset into `N` partitions,
|
||||||
and then use **Product Quantization** to compress vectors in each partition.
|
and then use **Product Quantization** to compress vectors in each partition.
|
||||||
* `DISKANN` (**Experimental**): organize the vector as a on-disk graph, where the vertices approximately
|
- `DiskANN` (**Experimental**): organize the vector as a on-disk graph, where the vertices approximately
|
||||||
represent the nearest neighbors of each vector.
|
represent the nearest neighbors of each vector.
|
||||||
|
|
||||||
## Creating an IVF_PQ Index
|
## Creating an IVF_PQ Index
|
||||||
|
|
||||||
Lance supports `IVF_PQ` index type by default.
|
Lance supports `IVF_PQ` index type by default.
|
||||||
|
|
||||||
=== "Python"
|
=== "Python"
|
||||||
|
|
||||||
Creating indexes is done via the [create_index](https://lancedb.github.io/lancedb/python/#lancedb.table.LanceTable.create_index) method.
|
Creating indexes is done via the [create_index](https://lancedb.github.io/lancedb/python/#lancedb.table.LanceTable.create_index) method.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
@@ -43,31 +47,63 @@ Lance supports `IVF_PQ` index type by default.
|
|||||||
tbl.create_index(num_partitions=256, num_sub_vectors=96)
|
tbl.create_index(num_partitions=256, num_sub_vectors=96)
|
||||||
```
|
```
|
||||||
|
|
||||||
=== "Javascript"
|
=== "Typescript"
|
||||||
```javascript
|
|
||||||
const vectordb = require('vectordb')
|
|
||||||
const db = await vectordb.connect('data/sample-lancedb')
|
|
||||||
|
|
||||||
let data = []
|
```typescript
|
||||||
for (let i = 0; i < 10_000; i++) {
|
--8<--- "docs/src/ann_indexes.ts:import"
|
||||||
data.push({vector: Array(1536).fill(i), id: `${i}`, content: "", longId: `${i}`},)
|
|
||||||
}
|
--8<-- "docs/src/ann_indexes.ts:ingest"
|
||||||
const table = await db.createTable('my_vectors', data)
|
|
||||||
await table.createIndex({ type: 'ivf_pq', column: 'vector', num_partitions: 256, num_sub_vectors: 96 })
|
|
||||||
```
|
```
|
||||||
|
|
||||||
- **metric** (default: "L2"): The distance metric to use. By default it uses euclidean distance "`L2`".
|
- **metric** (default: "L2"): The distance metric to use. By default it uses euclidean distance "`L2`".
|
||||||
We also support "cosine" and "dot" distance as well.
|
We also support "cosine" and "dot" distance as well.
|
||||||
- **num_partitions** (default: 256): The number of partitions of the index.
|
- **num_partitions** (default: 256): The number of partitions of the index.
|
||||||
- **num_sub_vectors** (default: 96): The number of sub-vectors (M) that will be created during Product Quantization (PQ).
|
- **num_sub_vectors** (default: 96): The number of sub-vectors (M) that will be created during Product Quantization (PQ).
|
||||||
For D dimensional vector, it will be divided into `M` of `D/M` sub-vectors, each of which is presented by
|
For D dimensional vector, it will be divided into `M` of `D/M` sub-vectors, each of which is presented by
|
||||||
a single PQ code.
|
a single PQ code.
|
||||||
|
|
||||||
<figure markdown>
|
<figure markdown>
|
||||||

|

|
||||||
<figcaption>IVF_PQ index with <code>num_partitions=2, num_sub_vectors=4</code></figcaption>
|
<figcaption>IVF_PQ index with <code>num_partitions=2, num_sub_vectors=4</code></figcaption>
|
||||||
</figure>
|
</figure>
|
||||||
|
|
||||||
|
### Use GPU to build vector index
|
||||||
|
|
||||||
|
Lance Python SDK has experimental GPU support for creating IVF index.
|
||||||
|
Using GPU for index creation requires [PyTorch>2.0](https://pytorch.org/) being installed.
|
||||||
|
|
||||||
|
You can specify the GPU device to train IVF partitions via
|
||||||
|
|
||||||
|
- **accelerator**: Specify to `cuda` or `mps` (on Apple Silicon) to enable GPU training.
|
||||||
|
|
||||||
|
=== "Linux"
|
||||||
|
|
||||||
|
<!-- skip-test -->
|
||||||
|
``` { .python .copy }
|
||||||
|
# Create index using CUDA on Nvidia GPUs.
|
||||||
|
tbl.create_index(
|
||||||
|
num_partitions=256,
|
||||||
|
num_sub_vectors=96,
|
||||||
|
accelerator="cuda"
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Macos"
|
||||||
|
|
||||||
|
<!-- skip-test -->
|
||||||
|
```python
|
||||||
|
# Create index using MPS on Apple Silicon.
|
||||||
|
tbl.create_index(
|
||||||
|
num_partitions=256,
|
||||||
|
num_sub_vectors=96,
|
||||||
|
accelerator="mps"
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
Trouble shootings:
|
||||||
|
|
||||||
|
If you see `AssertionError: Torch not compiled with CUDA enabled`, you need to [install
|
||||||
|
PyTorch with CUDA support](https://pytorch.org/get-started/locally/).
|
||||||
|
|
||||||
## Querying an ANN Index
|
## Querying an ANN Index
|
||||||
|
|
||||||
@@ -86,48 +122,43 @@ There are a couple of parameters that can be used to fine-tune the search:
|
|||||||
Note: refine_factor is only applicable if an ANN index is present. If specified on a table without an ANN index, it is ignored.
|
Note: refine_factor is only applicable if an ANN index is present. If specified on a table without an ANN index, it is ignored.
|
||||||
|
|
||||||
=== "Python"
|
=== "Python"
|
||||||
|
|
||||||
```python
|
```python
|
||||||
tbl.search(np.random.random((1536))) \
|
tbl.search(np.random.random((1536))) \
|
||||||
.limit(2) \
|
.limit(2) \
|
||||||
.nprobes(20) \
|
.nprobes(20) \
|
||||||
.refine_factor(10) \
|
.refine_factor(10) \
|
||||||
.to_df()
|
.to_pandas()
|
||||||
```
|
```
|
||||||
```
|
|
||||||
vector item score
|
```text
|
||||||
|
vector item _distance
|
||||||
0 [0.44949695, 0.8444449, 0.06281311, 0.23338133... item 1141 103.575333
|
0 [0.44949695, 0.8444449, 0.06281311, 0.23338133... item 1141 103.575333
|
||||||
1 [0.48587373, 0.269207, 0.15095535, 0.65531915,... item 3953 108.393867
|
1 [0.48587373, 0.269207, 0.15095535, 0.65531915,... item 3953 108.393867
|
||||||
```
|
```
|
||||||
|
|
||||||
=== "Javascript"
|
=== "Typescript"
|
||||||
```javascript
|
|
||||||
const results_1 = await table
|
```typescript
|
||||||
.search(Array(1536).fill(1.2))
|
--8<-- "docs/src/ann_indexes.ts:search1"
|
||||||
.limit(2)
|
|
||||||
.nprobes(20)
|
|
||||||
.refineFactor(10)
|
|
||||||
.execute()
|
|
||||||
```
|
```
|
||||||
|
|
||||||
The search will return the data requested in addition to the score of each item.
|
The search will return the data requested in addition to the distance of each item.
|
||||||
|
|
||||||
**Note:** The score is the distance between the query vector and the element. A lower number means that the result is more relevant.
|
|
||||||
|
|
||||||
### Filtering (where clause)
|
### Filtering (where clause)
|
||||||
|
|
||||||
You can further filter the elements returned by a search using a where clause.
|
You can further filter the elements returned by a search using a where clause.
|
||||||
|
|
||||||
=== "Python"
|
=== "Python"
|
||||||
|
|
||||||
```python
|
```python
|
||||||
tbl.search(np.random.random((1536))).where("item != 'item 1141'").to_df()
|
tbl.search(np.random.random((1536))).where("item != 'item 1141'").to_pandas()
|
||||||
```
|
```
|
||||||
|
|
||||||
=== "Javascript"
|
=== "Typescript"
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const results_2 = await table
|
--8<-- "docs/src/ann_indexes.ts:search2"
|
||||||
.search(Array(1536).fill(1.2))
|
|
||||||
.where("id != '1141'")
|
|
||||||
.execute()
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Projections (select clause)
|
### Projections (select clause)
|
||||||
@@ -135,48 +166,49 @@ You can further filter the elements returned by a search using a where clause.
|
|||||||
You can select the columns returned by the query using a select clause.
|
You can select the columns returned by the query using a select clause.
|
||||||
|
|
||||||
=== "Python"
|
=== "Python"
|
||||||
|
|
||||||
```python
|
```python
|
||||||
tbl.search(np.random.random((1536))).select(["vector"]).to_df()
|
tbl.search(np.random.random((1536))).select(["vector"]).to_pandas()
|
||||||
```
|
```
|
||||||
```
|
|
||||||
vector score
|
|
||||||
|
```text
|
||||||
|
vector _distance
|
||||||
0 [0.30928212, 0.022668175, 0.1756372, 0.4911822... 93.971092
|
0 [0.30928212, 0.022668175, 0.1756372, 0.4911822... 93.971092
|
||||||
1 [0.2525465, 0.01723831, 0.261568, 0.002007689,... 95.173485
|
1 [0.2525465, 0.01723831, 0.261568, 0.002007689,... 95.173485
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
=== "Javascript"
|
=== "Typescript"
|
||||||
```javascript
|
|
||||||
const results_3 = await table
|
```typescript
|
||||||
.search(Array(1536).fill(1.2))
|
--8<-- "docs/src/ann_indexes.ts:search3"
|
||||||
.select(["id"])
|
|
||||||
.execute()
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## FAQ
|
## FAQ
|
||||||
|
|
||||||
### When is it necessary to create an ANN vector index.
|
### When is it necessary to create an ANN vector index?
|
||||||
|
|
||||||
`LanceDB` has manually tuned SIMD code for computing vector distances.
|
`LanceDB` has manually-tuned SIMD code for computing vector distances.
|
||||||
In our benchmarks, computing 100K pairs of 1K dimension vectors only take less than 20ms.
|
In our benchmarks, computing 100K pairs of 1K dimension vectors takes **less than 20ms**.
|
||||||
For small dataset (<100K rows) or the applications which can accept 100ms latency, vector indices are usually not necessary.
|
For small datasets (< 100K rows) or applications that can accept 100ms latency, vector indices are usually not necessary.
|
||||||
|
|
||||||
For large-scale or higher dimension vectors, it is beneficial to create vector index.
|
For large-scale or higher dimension vectors, it is beneficial to create vector index.
|
||||||
|
|
||||||
### How big is my index, and how many memory will it take.
|
### How big is my index, and how many memory will it take?
|
||||||
|
|
||||||
In LanceDB, all vector indices are disk-based, meaning that when responding to a vector query, only the relevant pages from the index file are loaded from disk and cached in memory. Additionally, each sub-vector is usually encoded into 1 byte PQ code.
|
In LanceDB, all vector indices are **disk-based**, meaning that when responding to a vector query, only the relevant pages from the index file are loaded from disk and cached in memory. Additionally, each sub-vector is usually encoded into 1 byte PQ code.
|
||||||
|
|
||||||
For example, with a 1024-dimension dataset, if we choose `num_sub_vectors=64`, each sub-vector has `1024 / 64 = 16` float32 numbers.
|
For example, with a 1024-dimension dataset, if we choose `num_sub_vectors=64`, each sub-vector has `1024 / 64 = 16` float32 numbers.
|
||||||
Product quantization can lead to approximately `16 * sizeof(float32) / 1 = 64` times of space reduction.
|
Product quantization can lead to approximately `16 * sizeof(float32) / 1 = 64` times of space reduction.
|
||||||
|
|
||||||
### How to choose `num_partitions` and `num_sub_vectors` for `IVF_PQ` index.
|
### How to choose `num_partitions` and `num_sub_vectors` for `IVF_PQ` index?
|
||||||
|
|
||||||
`num_partitions` is used to decide how many partitions the first level `IVF` index uses.
|
`num_partitions` is used to decide how many partitions the first level `IVF` index uses.
|
||||||
Higher number of partitions could lead to more efficient I/O during queries and better accuracy, but it takes much more time to train.
|
Higher number of partitions could lead to more efficient I/O during queries and better accuracy, but it takes much more time to train.
|
||||||
On `SIFT-1M` dataset, our benchmark shows that keeping each partition 1K-4K rows lead to a good latency / recall.
|
On `SIFT-1M` dataset, our benchmark shows that keeping each partition 1K-4K rows lead to a good latency / recall.
|
||||||
|
|
||||||
`num_sub_vectors` decides how many Product Quantization code to generate on each vector. Because
|
`num_sub_vectors` specifies how many Product Quantization (PQ) short codes to generate on each vector. Because
|
||||||
Product Quantization is a lossy compression of the original vector, the more `num_sub_vectors` usually results to
|
PQ is a lossy compression of the original vector, a higher `num_sub_vectors` usually results in
|
||||||
less space distortion, and thus yield better accuracy. However, similarly, more `num_sub_vectors` causes heavier I/O and
|
less space distortion, and thus yields better accuracy. However, a higher `num_sub_vectors` also causes heavier I/O and
|
||||||
more PQ computation, thus, higher latency. `dimension / num_sub_vectors` should be aligned with 8 for better SIMD efficiency.
|
more PQ computation, and thus, higher latency. `dimension / num_sub_vectors` should be a multiple of 8 for optimum SIMD efficiency.
|
||||||
|
|||||||
53
docs/src/ann_indexes.ts
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
// --8<-- [start:import]
|
||||||
|
import * as vectordb from "vectordb";
|
||||||
|
// --8<-- [end:import]
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
// --8<-- [start:ingest]
|
||||||
|
const db = await vectordb.connect("data/sample-lancedb");
|
||||||
|
|
||||||
|
let data = [];
|
||||||
|
for (let i = 0; i < 10_000; i++) {
|
||||||
|
data.push({
|
||||||
|
vector: Array(1536).fill(i),
|
||||||
|
id: `${i}`,
|
||||||
|
content: "",
|
||||||
|
longId: `${i}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const table = await db.createTable("my_vectors", data);
|
||||||
|
await table.createIndex({
|
||||||
|
type: "ivf_pq",
|
||||||
|
column: "vector",
|
||||||
|
num_partitions: 16,
|
||||||
|
num_sub_vectors: 48,
|
||||||
|
});
|
||||||
|
// --8<-- [end:ingest]
|
||||||
|
|
||||||
|
// --8<-- [start:search1]
|
||||||
|
const results_1 = await table
|
||||||
|
.search(Array(1536).fill(1.2))
|
||||||
|
.limit(2)
|
||||||
|
.nprobes(20)
|
||||||
|
.refineFactor(10)
|
||||||
|
.execute();
|
||||||
|
// --8<-- [end:search1]
|
||||||
|
|
||||||
|
// --8<-- [start:search2]
|
||||||
|
const results_2 = await table
|
||||||
|
.search(Array(1536).fill(1.2))
|
||||||
|
.where("id != '1141'")
|
||||||
|
.limit(2)
|
||||||
|
.execute();
|
||||||
|
// --8<-- [end:search2]
|
||||||
|
|
||||||
|
// --8<-- [start:search3]
|
||||||
|
const results_3 = await table
|
||||||
|
.search(Array(1536).fill(1.2))
|
||||||
|
.select(["id"])
|
||||||
|
.limit(2)
|
||||||
|
.execute();
|
||||||
|
// --8<-- [end:search3]
|
||||||
|
|
||||||
|
console.log("Ann indexes: done");
|
||||||
|
})();
|
||||||
BIN
docs/src/assets/dog_clip_output.png
Normal file
|
After Width: | Height: | Size: 342 KiB |
BIN
docs/src/assets/ecosystem-illustration.png
Normal file
|
After Width: | Height: | Size: 104 KiB |
BIN
docs/src/assets/embedding_intro.png
Normal file
|
After Width: | Height: | Size: 245 KiB |
BIN
docs/src/assets/embeddings_api.png
Normal file
|
After Width: | Height: | Size: 83 KiB |
|
Before Width: | Height: | Size: 266 KiB After Width: | Height: | Size: 107 KiB |
BIN
docs/src/assets/ivfpq_ivf_desc.webp
Normal file
|
After Width: | Height: | Size: 23 KiB |
BIN
docs/src/assets/ivfpq_pq_desc.png
Normal file
|
After Width: | Height: | Size: 60 KiB |
BIN
docs/src/assets/ivfpq_query_vector.webp
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
docs/src/assets/knn_search.png
Normal file
|
After Width: | Height: | Size: 34 KiB |
BIN
docs/src/assets/lancedb_and_lance.png
Normal file
|
After Width: | Height: | Size: 131 KiB |
BIN
docs/src/assets/lancedb_cloud.png
Normal file
|
After Width: | Height: | Size: 82 KiB |
|
Before Width: | Height: | Size: 190 KiB After Width: | Height: | Size: 113 KiB |
BIN
docs/src/assets/lancedb_oss_and_cloud.png
Normal file
|
After Width: | Height: | Size: 97 KiB |
BIN
docs/src/assets/lancedb_storage_tradeoffs.png
Normal file
|
After Width: | Height: | Size: 224 KiB |
BIN
docs/src/assets/langchain.png
Normal file
|
After Width: | Height: | Size: 170 KiB |
BIN
docs/src/assets/llama-index.jpg
Normal file
|
After Width: | Height: | Size: 4.9 KiB |
BIN
docs/src/assets/prompttools.jpeg
Normal file
|
After Width: | Height: | Size: 1.7 MiB |
BIN
docs/src/assets/recall-vs-latency.webp
Normal file
|
After Width: | Height: | Size: 26 KiB |
BIN
docs/src/assets/vector-db-basics.png
Normal file
|
After Width: | Height: | Size: 210 KiB |
BIN
docs/src/assets/vercel-template.gif
Normal file
|
After Width: | Height: | Size: 205 KiB |
BIN
docs/src/assets/voxel.gif
Normal file
|
After Width: | Height: | Size: 953 KiB |
@@ -1,126 +1,275 @@
|
|||||||
# Basic LanceDB Functionality
|
# Quick start
|
||||||
|
|
||||||
We'll cover the basics of using LanceDB on your local machine in this section.
|
!!! info "LanceDB can be run in a number of ways:"
|
||||||
|
|
||||||
??? info "LanceDB runs embedded on your backend application, so there is no need to run a separate server."
|
* Embedded within an existing backend (like your Django, Flask, Node.js or FastAPI application)
|
||||||
|
* Connected to directly from a client application like a Jupyter notebook for analytical workloads
|
||||||
|
* Deployed as a remote serverless database
|
||||||
|
|
||||||
<img src="../assets/lancedb_embedded_explanation.png" width="650px" />
|

|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
=== "Python"
|
=== "Python"
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
pip install lancedb
|
pip install lancedb
|
||||||
```
|
```
|
||||||
|
|
||||||
=== "Javascript"
|
=== "Typescript"
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
npm install vectordb
|
npm install vectordb
|
||||||
```
|
```
|
||||||
|
|
||||||
|
=== "Rust"
|
||||||
|
|
||||||
|
!!! warning "Rust SDK is experimental, might introduce breaking changes in the near future"
|
||||||
|
|
||||||
|
```shell
|
||||||
|
cargo add vectordb
|
||||||
|
```
|
||||||
|
|
||||||
|
!!! info "To use the vectordb create, you first need to install protobuf."
|
||||||
|
|
||||||
|
=== "macOS"
|
||||||
|
|
||||||
|
```shell
|
||||||
|
brew install protobuf
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Ubuntu/Debian"
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo apt install -y protobuf-compiler libssl-dev
|
||||||
|
```
|
||||||
|
|
||||||
|
!!! info "Please also make sure you're using the same version of Arrow as in the [vectordb crate](https://github.com/lancedb/lancedb/blob/main/Cargo.toml)"
|
||||||
|
|
||||||
## How to connect to a database
|
## How to connect to a database
|
||||||
|
|
||||||
=== "Python"
|
=== "Python"
|
||||||
|
|
||||||
```python
|
```python
|
||||||
import lancedb
|
import lancedb
|
||||||
uri = "data/sample-lancedb"
|
uri = "data/sample-lancedb"
|
||||||
db = lancedb.connect(uri)
|
db = lancedb.connect(uri)
|
||||||
```
|
```
|
||||||
|
|
||||||
LanceDB will create the directory if it doesn't exist (including parent directories).
|
=== "Typescript"
|
||||||
|
|
||||||
If you need a reminder of the uri, use the `db.uri` property.
|
```typescript
|
||||||
|
--8<-- "docs/src/basic_legacy.ts:import"
|
||||||
|
|
||||||
=== "Javascript"
|
--8<-- "docs/src/basic_legacy.ts:open_db"
|
||||||
```javascript
|
```
|
||||||
const lancedb = require("vectordb");
|
|
||||||
|
|
||||||
const uri = "data/sample-lancedb";
|
=== "Rust"
|
||||||
const db = await lancedb.connect(uri);
|
|
||||||
```
|
|
||||||
|
|
||||||
LanceDB will create the directory if it doesn't exist (including parent directories).
|
|
||||||
|
|
||||||
If you need a reminder of the uri, you can call `db.uri()`.
|
```rust
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> Result<()> {
|
||||||
|
--8<-- "rust/vectordb/examples/simple.rs:connect"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
!!! info "See [examples/simple.rs](https://github.com/lancedb/lancedb/tree/main/rust/vectordb/examples/simple.rs) for a full working example."
|
||||||
|
|
||||||
|
LanceDB will create the directory if it doesn't exist (including parent directories).
|
||||||
|
|
||||||
|
If you need a reminder of the uri, you can call `db.uri()`.
|
||||||
|
|
||||||
## How to create a table
|
## How to create a table
|
||||||
|
|
||||||
=== "Python"
|
=== "Python"
|
||||||
|
|
||||||
|
```python
|
||||||
|
tbl = db.create_table("my_table",
|
||||||
|
data=[{"vector": [3.1, 4.1], "item": "foo", "price": 10.0},
|
||||||
|
{"vector": [5.9, 26.5], "item": "bar", "price": 20.0}])
|
||||||
|
```
|
||||||
|
|
||||||
|
If the table already exists, LanceDB will raise an error by default.
|
||||||
|
If you want to overwrite the table, you can pass in `mode="overwrite"`
|
||||||
|
to the `create_table` method.
|
||||||
|
|
||||||
|
You can also pass in a pandas DataFrame directly:
|
||||||
|
|
||||||
|
```python
|
||||||
|
import pandas as pd
|
||||||
|
df = pd.DataFrame([{"vector": [3.1, 4.1], "item": "foo", "price": 10.0},
|
||||||
|
{"vector": [5.9, 26.5], "item": "bar", "price": 20.0}])
|
||||||
|
tbl = db.create_table("table_from_df", data=df)
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Typescript"
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
--8<-- "docs/src/basic_legacy.ts:create_table"
|
||||||
|
```
|
||||||
|
|
||||||
|
If the table already exists, LanceDB will raise an error by default.
|
||||||
|
If you want to overwrite the table, you can pass in `mode="overwrite"`
|
||||||
|
to the `createTable` function.
|
||||||
|
|
||||||
|
=== "Rust"
|
||||||
|
|
||||||
|
```rust
|
||||||
|
use arrow_schema::{DataType, Schema, Field};
|
||||||
|
use arrow_array::{RecordBatch, RecordBatchIterator};
|
||||||
|
|
||||||
|
--8<-- "rust/vectordb/examples/simple.rs:create_table"
|
||||||
|
```
|
||||||
|
|
||||||
|
If the table already exists, LanceDB will raise an error by default.
|
||||||
|
|
||||||
|
!!! info "Under the hood, LanceDB is converting the input data into an Apache Arrow table and persisting it to disk in [Lance format](https://www.github.com/lancedb/lance)."
|
||||||
|
|
||||||
|
### Creating an empty table
|
||||||
|
|
||||||
|
Sometimes you may not have the data to insert into the table at creation time.
|
||||||
|
In this case, you can create an empty table and specify the schema.
|
||||||
|
|
||||||
|
=== "Python"
|
||||||
|
|
||||||
```python
|
```python
|
||||||
tbl = db.create_table("my_table",
|
import pyarrow as pa
|
||||||
data=[{"vector": [3.1, 4.1], "item": "foo", "price": 10.0},
|
schema = pa.schema([pa.field("vector", pa.list_(pa.float32(), list_size=2))])
|
||||||
{"vector": [5.9, 26.5], "item": "bar", "price": 20.0}])
|
tbl = db.create_table("empty_table", schema=schema)
|
||||||
```
|
```
|
||||||
|
|
||||||
If the table already exists, LanceDB will raise an error by default.
|
=== "Typescript"
|
||||||
If you want to overwrite the table, you can pass in `mode="overwrite"`
|
|
||||||
to the `create_table` method.
|
|
||||||
|
|
||||||
You can also pass in a pandas DataFrame directly:
|
```typescript
|
||||||
```python
|
--8<-- "docs/src/basic_legacy.ts:create_empty_table"
|
||||||
import pandas as pd
|
```
|
||||||
df = pd.DataFrame([{"vector": [3.1, 4.1], "item": "foo", "price": 10.0},
|
|
||||||
{"vector": [5.9, 26.5], "item": "bar", "price": 20.0}])
|
|
||||||
tbl = db.create_table("table_from_df", data=df)
|
|
||||||
```
|
|
||||||
|
|
||||||
=== "Javascript"
|
=== "Rust"
|
||||||
```javascript
|
|
||||||
const tb = await db.createTable("my_table",
|
|
||||||
data=[{"vector": [3.1, 4.1], "item": "foo", "price": 10.0},
|
|
||||||
{"vector": [5.9, 26.5], "item": "bar", "price": 20.0}])
|
|
||||||
```
|
|
||||||
|
|
||||||
!!! warning
|
|
||||||
|
|
||||||
If the table already exists, LanceDB will raise an error by default.
|
```rust
|
||||||
If you want to overwrite the table, you can pass in `mode="overwrite"`
|
--8<-- "rust/vectordb/examples/simple.rs:create_empty_table"
|
||||||
to the `createTable` function.
|
```
|
||||||
|
|
||||||
??? info "Under the hood, LanceDB is converting the input data into an Apache Arrow table and persisting it to disk in [Lance format](https://www.github.com/lancedb/lance)."
|
|
||||||
|
|
||||||
## How to open an existing table
|
## How to open an existing table
|
||||||
|
|
||||||
Once created, you can open a table using the following code:
|
Once created, you can open a table using the following code:
|
||||||
|
|
||||||
=== "Python"
|
=== "Python"
|
||||||
```python
|
|
||||||
tbl = db.open_table("my_table")
|
|
||||||
```
|
|
||||||
|
|
||||||
If you forget the name of your table, you can always get a listing of all table names:
|
```python
|
||||||
|
tbl = db.open_table("my_table")
|
||||||
|
```
|
||||||
|
|
||||||
```python
|
=== "Typescript"
|
||||||
print(db.table_names())
|
|
||||||
```
|
```typescript
|
||||||
|
const tbl = await db.openTable("myTable");
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Rust"
|
||||||
|
|
||||||
|
```rust
|
||||||
|
--8<-- "rust/vectordb/examples/simple.rs:open_with_existing_file"
|
||||||
|
```
|
||||||
|
|
||||||
|
If you forget the name of your table, you can always get a listing of all table names:
|
||||||
|
|
||||||
|
=== "Python"
|
||||||
|
|
||||||
|
```python
|
||||||
|
print(db.table_names())
|
||||||
|
```
|
||||||
|
|
||||||
=== "Javascript"
|
=== "Javascript"
|
||||||
```javascript
|
|
||||||
const tbl = await db.openTable("my_table");
|
|
||||||
```
|
|
||||||
|
|
||||||
If you forget the name of your table, you can always get a listing of all table names:
|
```javascript
|
||||||
|
console.log(await db.tableNames());
|
||||||
|
```
|
||||||
|
|
||||||
```javascript
|
=== "Rust"
|
||||||
console.log(await db.tableNames());
|
|
||||||
```
|
```rust
|
||||||
|
--8<-- "rust/vectordb/examples/simple.rs:list_names"
|
||||||
|
```
|
||||||
|
|
||||||
## How to add data to a table
|
## How to add data to a table
|
||||||
|
|
||||||
After a table has been created, you can always add more data to it using
|
After a table has been created, you can always add more data to it using
|
||||||
|
|
||||||
=== "Python"
|
=== "Python"
|
||||||
```python
|
|
||||||
df = pd.DataFrame([{"vector": [1.3, 1.4], "item": "fizz", "price": 100.0},
|
|
||||||
{"vector": [9.5, 56.2], "item": "buzz", "price": 200.0}])
|
|
||||||
tbl.add(df)
|
|
||||||
```
|
|
||||||
|
|
||||||
=== "Javascript"
|
```python
|
||||||
```javascript
|
|
||||||
await tbl.add([{vector: [1.3, 1.4], item: "fizz", price: 100.0},
|
# Option 1: Add a list of dicts to a table
|
||||||
{vector: [9.5, 56.2], item: "buzz", price: 200.0}])
|
data = [{"vector": [1.3, 1.4], "item": "fizz", "price": 100.0},
|
||||||
```
|
{"vector": [9.5, 56.2], "item": "buzz", "price": 200.0}]
|
||||||
|
tbl.add(data)
|
||||||
|
|
||||||
|
# Option 2: Add a pandas DataFrame to a table
|
||||||
|
df = pd.DataFrame(data)
|
||||||
|
tbl.add(data)
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Typescript"
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
--8<-- "docs/src/basic_legacy.ts:add"
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Rust"
|
||||||
|
|
||||||
|
```rust
|
||||||
|
--8<-- "rust/vectordb/examples/simple.rs:add"
|
||||||
|
```
|
||||||
|
|
||||||
|
## How to search for (approximate) nearest neighbors
|
||||||
|
|
||||||
|
Once you've embedded the query, you can find its nearest neighbors using the following code:
|
||||||
|
|
||||||
|
=== "Python"
|
||||||
|
|
||||||
|
```python
|
||||||
|
tbl.search([100, 100]).limit(2).to_pandas()
|
||||||
|
```
|
||||||
|
|
||||||
|
This returns a pandas DataFrame with the results.
|
||||||
|
|
||||||
|
=== "Typescript"
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
--8<-- "docs/src/basic_legacy.ts:search"
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Rust"
|
||||||
|
|
||||||
|
```rust
|
||||||
|
use futures::TryStreamExt;
|
||||||
|
|
||||||
|
--8<-- "rust/vectordb/examples/simple.rs:search"
|
||||||
|
```
|
||||||
|
|
||||||
|
By default, LanceDB runs a brute-force scan over dataset to find the K nearest neighbours (KNN).
|
||||||
|
For tables with more than 50K vectors, creating an ANN index is recommended to speed up search performance.
|
||||||
|
|
||||||
|
=== "Python"
|
||||||
|
|
||||||
|
```py
|
||||||
|
tbl.create_index()
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Typescript"
|
||||||
|
|
||||||
|
```{.typescript .ignore}
|
||||||
|
--8<-- "docs/src/basic_legacy.ts:create_index"
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Rust"
|
||||||
|
|
||||||
|
```rust
|
||||||
|
--8<-- "rust/vectordb/examples/simple.rs:create_index"
|
||||||
|
```
|
||||||
|
|
||||||
|
Check [Approximate Nearest Neighbor (ANN) Indexes](/ann_indices.md) section for more details.
|
||||||
|
|
||||||
## How to delete rows from a table
|
## How to delete rows from a table
|
||||||
|
|
||||||
@@ -129,20 +278,27 @@ which rows to delete, provide a filter that matches on the metadata columns.
|
|||||||
This can delete any number of rows that match the filter.
|
This can delete any number of rows that match the filter.
|
||||||
|
|
||||||
=== "Python"
|
=== "Python"
|
||||||
```python
|
|
||||||
tbl.delete('item = "fizz"')
|
|
||||||
```
|
|
||||||
|
|
||||||
=== "Javascript"
|
```python
|
||||||
```javascript
|
tbl.delete('item = "fizz"')
|
||||||
await tbl.delete('item = "fizz"')
|
```
|
||||||
```
|
|
||||||
|
=== "Typescript"
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
--8<-- "docs/src/basic_legacy.ts:delete"
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Rust"
|
||||||
|
|
||||||
|
```rust
|
||||||
|
--8<-- "rust/vectordb/examples/simple.rs:delete"
|
||||||
|
```
|
||||||
|
|
||||||
The deletion predicate is a SQL expression that supports the same expressions
|
The deletion predicate is a SQL expression that supports the same expressions
|
||||||
as the `where()` clause on a search. They can be as simple or complex as needed.
|
as the `where()` clause on a search. They can be as simple or complex as needed.
|
||||||
To see what expressions are supported, see the [SQL filters](sql.md) section.
|
To see what expressions are supported, see the [SQL filters](sql.md) section.
|
||||||
|
|
||||||
|
|
||||||
=== "Python"
|
=== "Python"
|
||||||
|
|
||||||
Read more: [lancedb.table.Table.delete][]
|
Read more: [lancedb.table.Table.delete][]
|
||||||
@@ -151,24 +307,51 @@ To see what expressions are supported, see the [SQL filters](sql.md) section.
|
|||||||
|
|
||||||
Read more: [vectordb.Table.delete](javascript/interfaces/Table.md#delete)
|
Read more: [vectordb.Table.delete](javascript/interfaces/Table.md#delete)
|
||||||
|
|
||||||
## How to search for (approximate) nearest neighbors
|
## How to remove a table
|
||||||
|
|
||||||
Once you've embedded the query, you can find its nearest neighbors using the following code:
|
Use the `drop_table()` method on the database to remove a table.
|
||||||
|
|
||||||
=== "Python"
|
=== "Python"
|
||||||
|
|
||||||
```python
|
```python
|
||||||
tbl.search([100, 100]).limit(2).to_df()
|
db.drop_table("my_table")
|
||||||
```
|
```
|
||||||
|
|
||||||
This returns a pandas DataFrame with the results.
|
This permanently removes the table and is not recoverable, unlike deleting rows.
|
||||||
|
By default, if the table does not exist an exception is raised. To suppress this,
|
||||||
|
you can pass in `ignore_missing=True`.
|
||||||
|
|
||||||
=== "Javascript"
|
=== "Typescript"
|
||||||
```javascript
|
|
||||||
const query = await tbl.search([100, 100]).limit(2).execute();
|
```typescript
|
||||||
|
--8<-- "docs/src/basic_legacy.ts:drop_table"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
This permanently removes the table and is not recoverable, unlike deleting rows.
|
||||||
|
If the table does not exist an exception is raised.
|
||||||
|
|
||||||
|
=== "Rust"
|
||||||
|
|
||||||
|
```rust
|
||||||
|
--8<-- "rust/vectordb/examples/simple.rs:drop_table"
|
||||||
|
```
|
||||||
|
|
||||||
|
!!! note "Bundling `vectordb` apps with Webpack"
|
||||||
|
|
||||||
|
If you're using the `vectordb` module in JavaScript, since LanceDB contains a prebuilt Node binary, you must configure `next.config.js` to exclude it from webpack. This is required for both using Next.js and deploying a LanceDB app on Vercel.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
/** @type {import('next').NextConfig} */
|
||||||
|
module.exports = ({
|
||||||
|
webpack(config) {
|
||||||
|
config.externals.push({ vectordb: 'vectordb' })
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
## What's next
|
## What's next
|
||||||
|
|
||||||
This section covered the very basics of the LanceDB API.
|
This section covered the very basics of using LanceDB. If you're learning about vector databases for the first time, you may want to read the page on [indexing](concepts/index_ivfpq.md) to get familiar with the concepts.
|
||||||
LanceDB supports many additional features when creating indices to speed up search and options for search.
|
|
||||||
These are contained in the next section of the documentation.
|
If you've already worked with other vector databases, you may want to read the [guides](guides/tables.md) to learn how to work with LanceDB in more detail.
|
||||||
|
|||||||
92
docs/src/basic_legacy.ts
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
// --8<-- [start:import]
|
||||||
|
import * as lancedb from "vectordb";
|
||||||
|
import { Schema, Field, Float32, FixedSizeList, Int32, Float16 } from "apache-arrow";
|
||||||
|
// --8<-- [end:import]
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Table as ArrowTable, Utf8 } from "apache-arrow";
|
||||||
|
|
||||||
|
const example = async () => {
|
||||||
|
fs.rmSync("data/sample-lancedb", { recursive: true, force: true });
|
||||||
|
// --8<-- [start:open_db]
|
||||||
|
const lancedb = require("vectordb");
|
||||||
|
const uri = "data/sample-lancedb";
|
||||||
|
const db = await lancedb.connect(uri);
|
||||||
|
// --8<-- [end:open_db]
|
||||||
|
|
||||||
|
// --8<-- [start:create_table]
|
||||||
|
const tbl = await db.createTable(
|
||||||
|
"myTable",
|
||||||
|
[
|
||||||
|
{ vector: [3.1, 4.1], item: "foo", price: 10.0 },
|
||||||
|
{ vector: [5.9, 26.5], item: "bar", price: 20.0 },
|
||||||
|
],
|
||||||
|
{ writeMode: lancedb.WriteMode.Overwrite }
|
||||||
|
);
|
||||||
|
// --8<-- [end:create_table]
|
||||||
|
|
||||||
|
// --8<-- [start:add]
|
||||||
|
const newData = Array.from({ length: 500 }, (_, i) => ({
|
||||||
|
vector: [i, i + 1],
|
||||||
|
item: "fizz",
|
||||||
|
price: i * 0.1,
|
||||||
|
}));
|
||||||
|
await tbl.add(newData);
|
||||||
|
// --8<-- [end:add]
|
||||||
|
|
||||||
|
// --8<-- [start:create_index]
|
||||||
|
await tbl.createIndex({
|
||||||
|
type: "ivf_pq",
|
||||||
|
num_partitions: 2,
|
||||||
|
num_sub_vectors: 2,
|
||||||
|
});
|
||||||
|
// --8<-- [end:create_index]
|
||||||
|
|
||||||
|
// --8<-- [start:create_empty_table]
|
||||||
|
const schema = new Schema([
|
||||||
|
new Field("id", new Int32()),
|
||||||
|
new Field("name", new Utf8()),
|
||||||
|
]);
|
||||||
|
const empty_tbl = await db.createTable({ name: "empty_table", schema });
|
||||||
|
// --8<-- [end:create_empty_table]
|
||||||
|
|
||||||
|
// --8<-- [start:create_f16_table]
|
||||||
|
const dim = 16
|
||||||
|
const total = 10
|
||||||
|
const f16_schema = new Schema([
|
||||||
|
new Field('id', new Int32()),
|
||||||
|
new Field(
|
||||||
|
'vector',
|
||||||
|
new FixedSizeList(dim, new Field('item', new Float16(), true)),
|
||||||
|
false
|
||||||
|
)
|
||||||
|
])
|
||||||
|
const data = lancedb.makeArrowTable(
|
||||||
|
Array.from(Array(total), (_, i) => ({
|
||||||
|
id: i,
|
||||||
|
vector: Array.from(Array(dim), Math.random)
|
||||||
|
})),
|
||||||
|
{ f16_schema }
|
||||||
|
)
|
||||||
|
const table = await db.createTable('f16_tbl', data)
|
||||||
|
// --8<-- [end:create_f16_table]
|
||||||
|
|
||||||
|
// --8<-- [start:search]
|
||||||
|
const query = await tbl.search([100, 100]).limit(2).execute();
|
||||||
|
// --8<-- [end:search]
|
||||||
|
console.log(query);
|
||||||
|
|
||||||
|
// --8<-- [start:delete]
|
||||||
|
await tbl.delete('item = "fizz"');
|
||||||
|
// --8<-- [end:delete]
|
||||||
|
|
||||||
|
// --8<-- [start:drop_table]
|
||||||
|
await db.dropTable("myTable");
|
||||||
|
// --8<-- [end:drop_table]
|
||||||
|
};
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
await example();
|
||||||
|
console.log("Basic example: done");
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
||||||
51
docs/src/cli_config.md
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
|
||||||
|
# CLI & Config
|
||||||
|
|
||||||
|
## LanceDB CLI
|
||||||
|
Once lanceDB is installed, you can access the CLI using `lancedb` command on the console.
|
||||||
|
|
||||||
|
```
|
||||||
|
lancedb
|
||||||
|
```
|
||||||
|
|
||||||
|
This lists out all the various command-line options available. You can get the usage or help for a particular command.
|
||||||
|
|
||||||
|
```
|
||||||
|
lancedb {command} --help
|
||||||
|
```
|
||||||
|
|
||||||
|
## LanceDB config
|
||||||
|
LanceDB uses a global config file to store certain settings. These settings are configurable using the lanceDB cli.
|
||||||
|
To view your config settings, you can use:
|
||||||
|
|
||||||
|
```
|
||||||
|
lancedb config
|
||||||
|
```
|
||||||
|
|
||||||
|
These config parameters can be tuned using the cli.
|
||||||
|
|
||||||
|
```
|
||||||
|
lancedb {config_name} --{argument}
|
||||||
|
```
|
||||||
|
|
||||||
|
## LanceDB Opt-in Diagnostics
|
||||||
|
When enabled, LanceDB will send anonymous events to help us improve LanceDB. These diagnostics are used only for error reporting and no data is collected. Error & stats allow us to automate certain aspects of bug reporting, prioritization of fixes and feature requests.
|
||||||
|
These diagnostics are opt-in and can be enabled or disabled using the `lancedb diagnostics` command. These are enabled by default.
|
||||||
|
|
||||||
|
### Get usage help
|
||||||
|
|
||||||
|
```
|
||||||
|
lancedb diagnostics --help
|
||||||
|
```
|
||||||
|
|
||||||
|
### Disable diagnostics
|
||||||
|
|
||||||
|
```
|
||||||
|
lancedb diagnostics --disabled
|
||||||
|
```
|
||||||
|
|
||||||
|
### Enable diagnostics
|
||||||
|
|
||||||
|
```
|
||||||
|
lancedb diagnostics --enabled
|
||||||
|
```
|
||||||
17
docs/src/cloud/index.md
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
# About LanceDB Cloud
|
||||||
|
|
||||||
|
LanceDB Cloud is a SaaS (software-as-a-service) solution that runs serverless in the cloud, clearly separating storage from compute. It's designed to be highly scalable without breaking the bank. LanceDB Cloud is currently in private beta with general availability coming soon, but you can apply for early access with the private beta release by signing up below.
|
||||||
|
|
||||||
|
[Try out LanceDB Cloud](https://noteforms.com/forms/lancedb-mailing-list-cloud-kty1o5?notionforms=1&utm_source=notionforms){ .md-button .md-button--primary }
|
||||||
|
|
||||||
|
## Architecture
|
||||||
|
|
||||||
|
LanceDB Cloud provides the same underlying fast vector store that powers the OSS version, but without the need to maintain your own infrastructure. Because it's serverless, you only pay for the storage you use, and you can scale compute up and down as needed depending on the size of your data and its associated index.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Transitioning from the OSS to the Cloud version
|
||||||
|
|
||||||
|
The OSS version of LanceDB is designed to be embedded in your application, and it runs in-process. This makes it incredibly simple to self-host your own AI retrieval workflows for RAG and more and build and test out your concepts on your own infrastructure. The OSS version is forever free, and you can continue to build and integrate LanceDB into your existing backend applications without any added costs.
|
||||||
|
|
||||||
|
Should you decide that you need a managed deployment in production, it's possible to seamlessly transition from the OSS to the cloud version by changing the connection string to point to a remote database instead of a local one. With LanceDB Cloud, you can take your AI application from development to production without major code changes or infrastructure burden.
|
||||||
62
docs/src/concepts/data_management.md
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
# Data management
|
||||||
|
|
||||||
|
This section covers concepts related to managing your data over time in LanceDB.
|
||||||
|
|
||||||
|
## A primer on Lance
|
||||||
|
|
||||||
|
Because LanceDB is built on top of the [Lance](https://lancedb.github.io/lance/) data format, it helps to understand some of its core ideas. Just like Apache Arrow, Lance is a fast columnar data format, but it has the added benefit of being versionable, query and train ML models on. Lance is designed to be used with simple and complex data types, like tabular data, images, videos audio, 3D point clouds (which are deeply nested) and more.
|
||||||
|
|
||||||
|
The following concepts are important to keep in mind:
|
||||||
|
|
||||||
|
- Data storage is columnar and is interoperable with other columnar formats (such as Parquet) via Arrow
|
||||||
|
- Data is divided into fragments that represent a subset of the data
|
||||||
|
- Data is versioned, with each insert operation creating a new version of the dataset and an update to the manifest that tracks versions via metadata
|
||||||
|
|
||||||
|
!!! note
|
||||||
|
1. First, each version contains metadata and just the new/updated data in your transaction. So if you have 100 versions, they aren't 100 duplicates of the same data. However, they do have 100x the metadata overhead of a single version, which can result in slower queries.
|
||||||
|
2. Second, these versions exist to keep LanceDB scalable and consistent. We do not immediately blow away old versions when creating new ones because other clients might be in the middle of querying the old version. It's important to retain older versions for as long as they might be queried.
|
||||||
|
|
||||||
|
## What are fragments?
|
||||||
|
|
||||||
|
Fragments are chunks of data in a Lance dataset. Each fragment includes multiple files that contain several columns in the chunk of data that it represents.
|
||||||
|
|
||||||
|
## Compaction
|
||||||
|
|
||||||
|
As you insert more data, your dataset will grow and you'll need to perform *compaction* to maintain query throughput (i.e., keep latencies down to a minimum). Compaction is the process of merging fragments together to reduce the amount of metadata that needs to be managed, and to reduce the number of files that need to be opened while scanning the dataset.
|
||||||
|
|
||||||
|
### How does compaction improve performance?
|
||||||
|
|
||||||
|
Compaction performs the following tasks in the background:
|
||||||
|
|
||||||
|
- Removes deleted rows from fragments
|
||||||
|
- Removes dropped columns from fragments
|
||||||
|
- Merges small fragments into larger ones
|
||||||
|
|
||||||
|
Depending on the use case and dataset, optimal compaction will have different requirements. As a rule of thumb:
|
||||||
|
|
||||||
|
- It’s always better to use *batch* inserts rather than adding 1 row at a time (to avoid too small fragments). If single-row inserts are unavoidable, run compaction on a regular basis to merge them into larger fragments.
|
||||||
|
- Keep the number of fragments under 100, which is suitable for most use cases (for *really* large datasets of >500M rows, more fragments might be needed)
|
||||||
|
|
||||||
|
## Deletion
|
||||||
|
|
||||||
|
Although Lance allows you to delete rows from a dataset, it does not actually delete the data immediately. It simply marks the row as deleted in the `DataFile` that represents a fragment. For a given version of the dataset, each fragment can have up to one deletion file (if no rows were ever deleted from that fragment, it will not have a deletion file). This is important to keep in mind because it means that the data is still there, and can be recovered if needed, as long as that version still exists based on your backup policy.
|
||||||
|
|
||||||
|
## Reindexing
|
||||||
|
|
||||||
|
Reindexing is the process of updating the index to account for new data, keeping good performance for queries. This applies to either a full-text search (FTS) index or a vector index. For ANN search, new data will always be included in query results, but queries on tables with unindexed data will fallback to slower search methods for the new parts of the table. This is another important operation to run periodically as your data grows, as it also improves performance. This is especially important if you're appending large amounts of data to an existing dataset.
|
||||||
|
|
||||||
|
!!! tip
|
||||||
|
When adding new data to a dataset that has an existing index (either FTS or vector), LanceDB doesn't immediately update the index until a reindex operation is complete.
|
||||||
|
|
||||||
|
Both LanceDB OSS and Cloud support reindexing, but the process (at least for now) is different for each, depending on the type of index.
|
||||||
|
|
||||||
|
When a reindex job is triggered in the background, the entire data is reindexed, but in the interim as new queries come in, LanceDB will combine results from the existing index with exhaustive kNN search on the new data. This is done to ensure that you're still searching on all your data, but it does come at a performance cost. The more data that you add without reindexing, the impact on latency (due to exhaustive search) can be noticeable.
|
||||||
|
|
||||||
|
### Vector reindex
|
||||||
|
|
||||||
|
* LanceDB Cloud supports incremental reindexing, where a background process will trigger a new index build for you automatically when new data is added to a dataset
|
||||||
|
* LanceDB OSS requires you to manually trigger a reindex operation -- we are working on adding incremental reindexing to LanceDB OSS as well
|
||||||
|
|
||||||
|
### FTS reindex
|
||||||
|
|
||||||
|
FTS reindexing is supported in both LanceDB OSS and Cloud, but requires that it's manually rebuilt once you have a significant enough amount of new data added that needs to be reindexed. We [updated](https://github.com/lancedb/lancedb/pull/762) Tantivy's default heap size from 128MB to 1GB in LanceDB to make it much faster to reindex, by up to 10x from the default settings.
|
||||||
104
docs/src/concepts/index_ivfpq.md
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
# Understanding LanceDB's IVF-PQ index
|
||||||
|
|
||||||
|
An ANN (Approximate Nearest Neighbors) index is a data structure that represents data in a way that makes it more efficient to search and retrieve. Using an ANN index is faster, but less accurate than kNN or brute force search because, in essence, the index is a lossy representation of the data.
|
||||||
|
|
||||||
|
LanceDB is fundamentally different from other vector databases in that it is built on top of [Lance](https://github.com/lancedb/lance), an open-source columnar data format designed for performant ML workloads and fast random access. Due to the design of Lance, LanceDB's indexing philosophy adopts a primarily *disk-based* indexing philosophy.
|
||||||
|
|
||||||
|
## IVF-PQ
|
||||||
|
|
||||||
|
IVF-PQ is a composite index that combines inverted file index (IVF) and product quantization (PQ). The implementation in LanceDB provides several parameters to fine-tune the index's size, query throughput, latency and recall, which are described later in this section.
|
||||||
|
|
||||||
|
### Product quantization
|
||||||
|
|
||||||
|
Quantization is a compression technique used to reduce the dimensionality of an embedding to speed up search.
|
||||||
|
|
||||||
|
Product quantization (PQ) works by dividing a large, high-dimensional vector of size into equally sized subvectors. Each subvector is assigned a "reproduction value" that maps to the nearest centroid of points for that subvector. The reproduction values are then assigned to a codebook using unique IDs, which can be used to reconstruct the original vector.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
It's important to remember that quantization is a *lossy process*, i.e., the reconstructed vector is not identical to the original vector. This results in a trade-off between the size of the index and the accuracy of the search results.
|
||||||
|
|
||||||
|
As an example, consider starting with 128-dimensional vector consisting of 32-bit floats. Quantizing it to an 8-bit integer vector with 4 dimensions as in the image above, we can significantly reduce memory requirements.
|
||||||
|
|
||||||
|
!!! example "Effect of quantization"
|
||||||
|
|
||||||
|
Original: `128 × 32 = 4096` bits
|
||||||
|
Quantized: `4 × 8 = 32` bits
|
||||||
|
|
||||||
|
Quantization results in a **128x** reduction in memory requirements for each vector in the index, which is substantial.
|
||||||
|
|
||||||
|
### Inverted file index
|
||||||
|
|
||||||
|
While PQ helps with reducing the size of the index, IVF primarily addresses search performance. The primary purpose of an inverted file index is to facilitate rapid and effective nearest neighbor search by narrowing down the search space.
|
||||||
|
|
||||||
|
In IVF, the PQ vector space is divided into *Voronoi cells*, which are essentially partitions that consist of all the points in the space that are within a threshold distance of the given region's seed point. These seed points are used to create an inverted index that correlates each centroid with a list of vectors in the space, allowing a search to be restricted to just a subset of vectors in the index.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
During query time, depending on where the query lands in vector space, it may be close to the border of multiple Voronoi cells, which could make the top-k results ambiguous and span across multiple cells. To address this, the IVF-PQ introduces the `nprobe` parameter, which controls the number of Voronoi cells to search during a query. The higher the `nprobe`, the more accurate the results, but the slower the query.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Putting it all together
|
||||||
|
|
||||||
|
We can combine the above concepts to understand how to build and query an IVF-PQ index in LanceDB.
|
||||||
|
|
||||||
|
### Construct index
|
||||||
|
|
||||||
|
There are three key parameters to set when constructing an IVF-PQ index:
|
||||||
|
|
||||||
|
* `metric`: Use an `L2` euclidean distance metric. We also support `dot` and `cosine` distance.
|
||||||
|
* `num_partitions`: The number of partitions in the IVF portion of the index.
|
||||||
|
* `num_sub_vectors`: The number of sub-vectors that will be created during Product Quantization (PQ).
|
||||||
|
|
||||||
|
In Python, the index can be created as follows:
|
||||||
|
|
||||||
|
```python
|
||||||
|
# Create and train the index for a 1536-dimensional vector
|
||||||
|
# Make sure you have enough data in the table for an effective training step
|
||||||
|
tbl.create_index(metric="L2", num_partitions=256, num_sub_vectors=96)
|
||||||
|
```
|
||||||
|
|
||||||
|
The `num_partitions` is usually chosen to target a particular number of vectors per partition. `num_sub_vectors` is typically chosen based on the desired recall and the dimensionality of the vector. See the [FAQs](#faq) below for best practices on choosing these parameters.
|
||||||
|
|
||||||
|
|
||||||
|
### Query the index
|
||||||
|
|
||||||
|
```python
|
||||||
|
# Search using a random 1536-dimensional embedding
|
||||||
|
tbl.search(np.random.random((1536))) \
|
||||||
|
.limit(2) \
|
||||||
|
.nprobes(20) \
|
||||||
|
.refine_factor(10) \
|
||||||
|
.to_pandas()
|
||||||
|
```
|
||||||
|
|
||||||
|
The above query will perform a search on the table `tbl` using the given query vector, with the following parameters:
|
||||||
|
|
||||||
|
* `limit`: The number of results to return
|
||||||
|
* `nprobes`: The number of probes determines the distribution of vector space. While a higher number enhances search accuracy, it also results in slower performance. Typically, setting `nprobes` to cover 5–10% of the dataset proves effective in achieving high recall with minimal latency.
|
||||||
|
* `refine_factor`: Refine the results by reading extra elements and re-ranking them in memory. A higher number makes the search more accurate but also slower (see the [FAQ](../faq.md#do-i-need-to-set-a-refine-factor-when-using-an-index) page for more details on this).
|
||||||
|
* `to_pandas()`: Convert the results to a pandas DataFrame
|
||||||
|
|
||||||
|
And there you have it! You now understand what an IVF-PQ index is, and how to create and query it in LanceDB.
|
||||||
|
|
||||||
|
|
||||||
|
## FAQ
|
||||||
|
|
||||||
|
### When is it necessary to create a vector index?
|
||||||
|
|
||||||
|
LanceDB has manually-tuned SIMD code for computing vector distances. In our benchmarks, computing 100K pairs of 1K dimension vectors takes **<20ms**. For small datasets (<100K rows) or applications that can accept up to 100ms latency, vector indices are usually not necessary.
|
||||||
|
|
||||||
|
For large-scale or higher dimension vectors, it is beneficial to create vector index.
|
||||||
|
|
||||||
|
### How big is my index, and how much memory will it take?
|
||||||
|
|
||||||
|
In LanceDB, all vector indices are disk-based, meaning that when responding to a vector query, only the relevant pages from the index file are loaded from disk and cached in memory. Additionally, each sub-vector is usually encoded into 1 byte PQ code.
|
||||||
|
|
||||||
|
For example, with 1024-dimension vectors, if we choose `num_sub_vectors = 64`, each sub-vector has `1024 / 64 = 16` float32 numbers. Product quantization can lead to approximately `16 * sizeof(float32) / 1 = 64` times of space reduction.
|
||||||
|
|
||||||
|
### How to choose `num_partitions` and `num_sub_vectors` for IVF_PQ index?
|
||||||
|
|
||||||
|
`num_partitions` is used to decide how many partitions the first level IVF index uses. Higher number of partitions could lead to more efficient I/O during queries and better accuracy, but it takes much more time to train. On SIFT-1M dataset, our benchmark shows that keeping each partition 1K-4K rows lead to a good latency/recall.
|
||||||
|
|
||||||
|
`num_sub_vectors` specifies how many PQ short codes to generate on each vector. Because PQ is a lossy compression of the original vector, a higher `num_sub_vectors` usually results in less space distortion, and thus yields better accuracy. However, a higher `num_sub_vectors` also causes heavier I/O and more PQ computation, and thus, higher latency. `dimension / num_sub_vectors` should be a multiple of 8 for optimum SIMD efficiency.
|
||||||
80
docs/src/concepts/storage.md
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
# Storage
|
||||||
|
|
||||||
|
LanceDB is among the only vector databases built on top of multiple modular components designed from the ground-up to be efficient on disk. This gives it the unique benefit of being flexible enough to support multiple storage backends, including local NVMe, EBS, EFS and many other third-party APIs that connect to the cloud.
|
||||||
|
|
||||||
|
It is important to understand the tradeoffs between cost and latency for your specific application and use case. This section will help you understand the tradeoffs between the different storage backends.
|
||||||
|
|
||||||
|
## Storage options
|
||||||
|
|
||||||
|
We've prepared a simple diagram to showcase the thought process that goes into choosing a storage backend when using LanceDB OSS, Cloud or Enterprise.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
When architecting your system, you'd typically ask yourself the following questions to decide on a storage option:
|
||||||
|
|
||||||
|
1. **Latency**: How fast do I need results? What do the p50 and also p95 look like?
|
||||||
|
2. **Scalability**: Can I scale up the amount of data and QPS easily?
|
||||||
|
3. **Cost**: To serve my application, what’s the all-in cost of *both* storage and serving infra?
|
||||||
|
4. **Reliability/Availability**: How does replication work? Is disaster recovery addressed?
|
||||||
|
|
||||||
|
## Tradeoffs
|
||||||
|
|
||||||
|
This section reviews the characteristics of each storage option in four dimensions: latency, scalability, cost and reliability.
|
||||||
|
|
||||||
|
**We begin with the lowest cost option, and end with the lowest latency option.**
|
||||||
|
|
||||||
|
### 1. S3 / GCS / Azure Blob Storage
|
||||||
|
|
||||||
|
!!! tip "Lowest cost, highest latency"
|
||||||
|
|
||||||
|
- **Latency** ⇒ Has the highest latency. p95 latency is also substantially worse than p50. In general you get results in the order of several hundred milliseconds
|
||||||
|
- **Scalability** ⇒ Infinite on storage, however, QPS will be limited by S3 concurrency limits
|
||||||
|
- **Cost** ⇒ Lowest (order of magnitude cheaper than other options)
|
||||||
|
- **Reliability/Availability** ⇒ Highly available, as blob storage like S3 are critical infrastructure that form the backbone of the internet.
|
||||||
|
|
||||||
|
Another important point to note is that LanceDB is designed to separate storage from compute, and the underlying Lance format stores the data in numerous immutable fragments. Due to these factors, LanceDB is a great storage option that addresses the _N + 1_ query problem. i.e., when a high query throughput is required, query processes can run in a stateless manner and be scaled up and down as needed.
|
||||||
|
|
||||||
|
### 2. EFS / GCS Filestore / Azure File Storage
|
||||||
|
|
||||||
|
!!! info "Moderately low cost, moderately low latency (<100ms)"
|
||||||
|
|
||||||
|
- **Latency** ⇒ Much better than object/blob storage but not as good as EBS/Local disk; < 100ms p95 achievable
|
||||||
|
- **Scalability** ⇒ High, but the bottleneck will be the IOPs limit, but when scaling you can provision multiple EFS volumes
|
||||||
|
- **Cost** ⇒ Significantly more expensive than S3 but still very cost effective compared to in-memory dbs. Inactive data in EFS is also automatically tiered to S3-level costs.
|
||||||
|
- **Reliability/Availability** ⇒ Highly available, as query nodes can go down without affecting EFS. However, EFS does not provide replication / backup - this must be managed manually.
|
||||||
|
|
||||||
|
A recommended best practice is to keep a copy of the data on S3 for disaster recovery scenarios. If any downtime is unacceptable, then you would need another EFS with a copy of the data. This is still much cheaper than EC2 instances holding multiple copies of the data.
|
||||||
|
|
||||||
|
### 3. Third-party storage solutions
|
||||||
|
|
||||||
|
Solutions like [MinIO](https://blog.min.io/lancedb-trusted-steed-against-data-complexity/), WekaFS, etc. that deliver S3 compatible API with much better performance than S3.
|
||||||
|
|
||||||
|
!!! info "Moderately low cost, moderately low latency (<100ms)"
|
||||||
|
|
||||||
|
- **Latency** ⇒ Should be similar latency to EFS, better than S3 (<100ms)
|
||||||
|
- **Scalability** ⇒ Up to the solutions architect, who can add as many nodes to their MinIO or other third-party provider's cluster as needed
|
||||||
|
- **Cost** ⇒ Definitely higher than S3. The cost can be marginally higher than EFS until you get to maybe >10TB scale with high utilization
|
||||||
|
- **Reliability/Availability** ⇒ These are all shareable by lots of nodes, quality/cost of replication/backup depends on the vendor
|
||||||
|
|
||||||
|
|
||||||
|
### 4. EBS / GCP Persistent Disk / Azure Managed Disk
|
||||||
|
|
||||||
|
!!! info "Very low latency (<30ms), higher cost"
|
||||||
|
|
||||||
|
- **Latency** ⇒ Very good, pretty close to local disk. You’re looking at <30ms latency in most cases
|
||||||
|
- **Scalability** ⇒ EBS is not shareable between instances. If deployed via k8s, it can be shared between pods that live on the same instance, but beyond that you would need to shard data or make an additional copy
|
||||||
|
- **Cost** ⇒ Higher than EFS. There are some hidden costs to EBS as well if you’re paying for IO.
|
||||||
|
- **Reliability/Availability** ⇒ Not shareable between instances but can be shared between pods on the same instance. Survives instance termination. No automatic backups.
|
||||||
|
|
||||||
|
Just like EFS, an EBS or persistent disk setup requires more manual work to manage data sharding, backups and capacity.
|
||||||
|
|
||||||
|
### 5. Local disk (SSD/NVMe)
|
||||||
|
|
||||||
|
!!! danger "Lowest latency (<10ms), highest cost"
|
||||||
|
|
||||||
|
- **Latency** ⇒ Lowest latency with modern NVMe drives, <10ms p95
|
||||||
|
- **Scalability** ⇒ Difficult to scale on cloud. Also need additional copies / sharding if QPS needs to be higher
|
||||||
|
- **Cost** ⇒ Highest cost; the main issue with keeping your application and storage tightly integrated is that it’s just not really possible to scale this up in cloud environments
|
||||||
|
- **Reliability/Availability** ⇒ If the instance goes down, so does your data. You have to be _very_ diligent about backing up your data
|
||||||
|
|
||||||
|
As a rule of thumb, local disk should be your storage option if you require absolutely *crazy low* latency and you’re willing to do a bunch of data management work to make it happen.
|
||||||
36
docs/src/concepts/vector_search.md
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
# Vector search
|
||||||
|
|
||||||
|
Vector search is a technique used to search for similar items based on their vector representations, called embeddings. It is also known as similarity search, nearest neighbor search, or approximate nearest neighbor search.
|
||||||
|
|
||||||
|
Raw data (e.g. text, images, audio, etc.) is converted into embeddings via an embedding model, which are then stored in a vector database like LanceDB. To perform similarity search at scale, an index is created on the stored embeddings, which can then used to perform fast lookups.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Embeddings
|
||||||
|
|
||||||
|
Modern machine learning models can be trained to convert raw data into embeddings, represented as arrays (or vectors) of floating point numbers of fixed dimensionality. What makes embeddings useful in practice is that the position of an embedding in vector space captures some of the semantics of the data, depending on the type of model and how it was trained. Points that are close to each other in vector space are considered similar (or appear in similar contexts), and points that are far away are considered dissimilar.
|
||||||
|
|
||||||
|
Large datasets of multi-modal data (text, audio, images, etc.) can be converted into embeddings with the appropriate model. Projecting the vectors' principal components in 2D space results in groups of vectors that represent similar concepts clustering together, as shown below.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Indexes
|
||||||
|
|
||||||
|
Embeddings for a given dataset are made searchable via an **index**. The index is constructed by using data structures that store the embeddings such that it's very efficient to perform scans and lookups on them. A key distinguishing feature of LanceDB is it uses a disk-based index: IVF-PQ, which is a variant of the Inverted File Index (IVF) that uses Product Quantization (PQ) to compress the embeddings.
|
||||||
|
|
||||||
|
See the [IVF-PQ](./index_ivfpq.md) page for more details on how it works.
|
||||||
|
|
||||||
|
## Brute force search
|
||||||
|
|
||||||
|
The simplest way to perform vector search is to perform a brute force search, without an index, where the distance between the query vector and all the vectors in the database are computed, with the top-k closest vectors returned. This is equivalent to a k-nearest neighbours (kNN) search in vector space.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
As you can imagine, the brute force approach is not scalable for datasets larger than a few hundred thousand vectors, as the latency of the search grows linearly with the size of the dataset. This is where approximate nearest neighbour (ANN) algorithms come in.
|
||||||
|
|
||||||
|
## Approximate nearest neighbour (ANN) search
|
||||||
|
|
||||||
|
Instead of performing an exhaustive search on the entire database for each and every query, approximate nearest neighbour (ANN) algorithms use an index to narrow down the search space, which significantly reduces query latency. The trade-off is that the results are not guaranteed to be the true nearest neighbors of the query, but are usually "good enough" for most use cases.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,142 +0,0 @@
|
|||||||
# Embedding Functions
|
|
||||||
|
|
||||||
Embeddings are high dimensional floating-point vector representations of your data or query.
|
|
||||||
Anything can be embedded using some embedding model or function.
|
|
||||||
For a given embedding function, the output will always have the same number of dimensions.
|
|
||||||
|
|
||||||
## Creating an embedding function
|
|
||||||
|
|
||||||
Any function that takes as input a batch (list) of data and outputs a batch (list) of embeddings
|
|
||||||
can be used by LanceDB as an embedding function. The input and output batch sizes should be the same.
|
|
||||||
|
|
||||||
### HuggingFace example
|
|
||||||
|
|
||||||
One popular free option would be to use the [sentence-transformers](https://www.sbert.net/) library from HuggingFace.
|
|
||||||
You can install this using pip: `pip install sentence-transformers`.
|
|
||||||
|
|
||||||
```python
|
|
||||||
from sentence_transformers import SentenceTransformer
|
|
||||||
|
|
||||||
name="paraphrase-albert-small-v2"
|
|
||||||
model = SentenceTransformer(name)
|
|
||||||
|
|
||||||
# used for both training and querying
|
|
||||||
def embed_func(batch):
|
|
||||||
return [model.encode(sentence) for sentence in batch]
|
|
||||||
```
|
|
||||||
|
|
||||||
Please note that currently HuggingFace is only supported in the Python SDK.
|
|
||||||
|
|
||||||
### OpenAI example
|
|
||||||
|
|
||||||
You can also use an external API like OpenAI to generate embeddings
|
|
||||||
|
|
||||||
=== "Python"
|
|
||||||
```python
|
|
||||||
import openai
|
|
||||||
import os
|
|
||||||
|
|
||||||
# Configuring the environment variable OPENAI_API_KEY
|
|
||||||
if "OPENAI_API_KEY" not in os.environ:
|
|
||||||
# OR set the key here as a variable
|
|
||||||
openai.api_key = "sk-..."
|
|
||||||
|
|
||||||
# verify that the API key is working
|
|
||||||
assert len(openai.Model.list()["data"]) > 0
|
|
||||||
|
|
||||||
def embed_func(c):
|
|
||||||
rs = openai.Embedding.create(input=c, engine="text-embedding-ada-002")
|
|
||||||
return [record["embedding"] for record in rs["data"]]
|
|
||||||
```
|
|
||||||
|
|
||||||
=== "Javascript"
|
|
||||||
```javascript
|
|
||||||
const lancedb = require("vectordb");
|
|
||||||
|
|
||||||
// You need to provide an OpenAI API key
|
|
||||||
const apiKey = "sk-..."
|
|
||||||
// The embedding function will create embeddings for the 'text' column
|
|
||||||
const embedding = new lancedb.OpenAIEmbeddingFunction('text', apiKey)
|
|
||||||
```
|
|
||||||
|
|
||||||
## Applying an embedding function
|
|
||||||
|
|
||||||
=== "Python"
|
|
||||||
Using an embedding function, you can apply it to raw data
|
|
||||||
to generate embeddings for each row.
|
|
||||||
|
|
||||||
Say if you have a pandas DataFrame with a `text` column that you want to be embedded,
|
|
||||||
you can use the [with_embeddings](https://lancedb.github.io/lancedb/python/#lancedb.embeddings.with_embeddings)
|
|
||||||
function to generate embeddings and add create a combined pyarrow table:
|
|
||||||
|
|
||||||
|
|
||||||
```python
|
|
||||||
import pandas as pd
|
|
||||||
from lancedb.embeddings import with_embeddings
|
|
||||||
|
|
||||||
df = pd.DataFrame([{"text": "pepperoni"},
|
|
||||||
{"text": "pineapple"}])
|
|
||||||
data = with_embeddings(embed_func, df)
|
|
||||||
|
|
||||||
# The output is used to create / append to a table
|
|
||||||
# db.create_table("my_table", data=data)
|
|
||||||
```
|
|
||||||
|
|
||||||
If your data is in a different column, you can specify the `column` kwarg to `with_embeddings`.
|
|
||||||
|
|
||||||
By default, LanceDB calls the function with batches of 1000 rows. This can be configured
|
|
||||||
using the `batch_size` parameter to `with_embeddings`.
|
|
||||||
|
|
||||||
LanceDB automatically wraps the function with retry and rate-limit logic to ensure the OpenAI
|
|
||||||
API call is reliable.
|
|
||||||
|
|
||||||
=== "Javascript"
|
|
||||||
Using an embedding function, you can apply it to raw data
|
|
||||||
to generate embeddings for each row.
|
|
||||||
|
|
||||||
You can just pass the embedding function created previously and LanceDB will automatically generate
|
|
||||||
embededings for your data.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
const db = await lancedb.connect("data/sample-lancedb");
|
|
||||||
const data = [
|
|
||||||
{ text: 'pepperoni' },
|
|
||||||
{ text: 'pineapple' }
|
|
||||||
]
|
|
||||||
|
|
||||||
const table = await db.createTable('vectors', data, embedding)
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## Searching with an embedding function
|
|
||||||
|
|
||||||
At inference time, you also need the same embedding function to embed your query text.
|
|
||||||
It's important that you use the same model / function otherwise the embedding vectors don't
|
|
||||||
belong in the same latent space and your results will be nonsensical.
|
|
||||||
|
|
||||||
=== "Python"
|
|
||||||
```python
|
|
||||||
query = "What's the best pizza topping?"
|
|
||||||
query_vector = embed_func([query])[0]
|
|
||||||
tbl.search(query_vector).limit(10).to_df()
|
|
||||||
```
|
|
||||||
|
|
||||||
The above snippet returns a pandas DataFrame with the 10 closest vectors to the query.
|
|
||||||
|
|
||||||
=== "Javascript"
|
|
||||||
```javascript
|
|
||||||
const results = await table
|
|
||||||
.search("What's the best pizza topping?")
|
|
||||||
.limit(10)
|
|
||||||
.execute()
|
|
||||||
```
|
|
||||||
|
|
||||||
The above snippet returns an array of records with the 10 closest vectors to the query.
|
|
||||||
|
|
||||||
|
|
||||||
## Roadmap
|
|
||||||
|
|
||||||
In the near future, we'll be integrating the embedding functions deeper into LanceDB<br/>.
|
|
||||||
The goal is that you just have to configure the function once when you create the table,
|
|
||||||
and then you'll never have to deal with embeddings / vectors after that unless you want to.
|
|
||||||
We'll also integrate more popular models and APIs.
|
|
||||||
212
docs/src/embeddings/api.md
Normal file
@@ -0,0 +1,212 @@
|
|||||||
|
To use your own custom embedding function, you can follow these 2 simple steps:
|
||||||
|
|
||||||
|
1. Create your embedding function by implementing the `EmbeddingFunction` interface
|
||||||
|
2. Register your embedding function in the global `EmbeddingFunctionRegistry`.
|
||||||
|
|
||||||
|
Let us see how this looks like in action.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
`EmbeddingFunction` and `EmbeddingFunctionRegistry` handle low-level details for serializing schema and model information as metadata. To build a custom embedding function, you don't have to worry about the finer details - simply focus on setting up the model and leave the rest to LanceDB.
|
||||||
|
|
||||||
|
## `TextEmbeddingFunction` interface
|
||||||
|
|
||||||
|
There is another optional layer of abstraction available: `TextEmbeddingFunction`. You can use this abstraction if your model isn't multi-modal in nature and only needs to operate on text. In such cases, both the source and vector fields will have the same work for vectorization, so you simply just need to setup the model and rest is handled by `TextEmbeddingFunction`. You can read more about the class and its attributes in the class reference.
|
||||||
|
|
||||||
|
Let's implement `SentenceTransformerEmbeddings` class. All you need to do is implement the `generate_embeddings()` and `ndims` function to handle the input types you expect and register the class in the global `EmbeddingFunctionRegistry`
|
||||||
|
|
||||||
|
```python
|
||||||
|
from lancedb.embeddings import register
|
||||||
|
from lancedb.util import attempt_import_or_raise
|
||||||
|
|
||||||
|
@register("sentence-transformers")
|
||||||
|
class SentenceTransformerEmbeddings(TextEmbeddingFunction):
|
||||||
|
name: str = "all-MiniLM-L6-v2"
|
||||||
|
# set more default instance vars like device, etc.
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
self._ndims = None
|
||||||
|
|
||||||
|
def generate_embeddings(self, texts):
|
||||||
|
return self._embedding_model().encode(list(texts), ...).tolist()
|
||||||
|
|
||||||
|
def ndims(self):
|
||||||
|
if self._ndims is None:
|
||||||
|
self._ndims = len(self.generate_embeddings("foo")[0])
|
||||||
|
return self._ndims
|
||||||
|
|
||||||
|
@cached(cache={})
|
||||||
|
def _embedding_model(self):
|
||||||
|
return sentence_transformers.SentenceTransformer(name)
|
||||||
|
```
|
||||||
|
|
||||||
|
This is a stripped down version of our implementation of `SentenceTransformerEmbeddings` that removes certain optimizations and defaul settings.
|
||||||
|
|
||||||
|
Now you can use this embedding function to create your table schema and that's it! you can then ingest data and run queries without manually vectorizing the inputs.
|
||||||
|
|
||||||
|
```python
|
||||||
|
from lancedb.pydantic import LanceModel, Vector
|
||||||
|
|
||||||
|
registry = EmbeddingFunctionRegistry.get_instance()
|
||||||
|
stransformer = registry.get("sentence-transformers").create()
|
||||||
|
|
||||||
|
class TextModelSchema(LanceModel):
|
||||||
|
vector: Vector(stransformer.ndims) = stransformer.VectorField()
|
||||||
|
text: str = stransformer.SourceField()
|
||||||
|
|
||||||
|
tbl = db.create_table("table", schema=TextModelSchema)
|
||||||
|
|
||||||
|
tbl.add(pd.DataFrame({"text": ["halo", "world"]}))
|
||||||
|
result = tbl.search("world").limit(5)
|
||||||
|
```
|
||||||
|
|
||||||
|
NOTE:
|
||||||
|
|
||||||
|
You can always implement the `EmbeddingFunction` interface directly if you want or need to, `TextEmbeddingFunction` just makes it much simpler and faster for you to do so, by setting up the boiler plat for text-specific use case
|
||||||
|
|
||||||
|
## Multi-modal embedding function example
|
||||||
|
You can also use the `EmbeddingFunction` interface to implement more complex workflows such as multi-modal embedding function support. LanceDB implements `OpenClipEmeddingFunction` class that suppports multi-modal seach. Here's the implementation that you can use as a reference to build your own multi-modal embedding functions.
|
||||||
|
|
||||||
|
```python
|
||||||
|
@register("open-clip")
|
||||||
|
class OpenClipEmbeddings(EmbeddingFunction):
|
||||||
|
name: str = "ViT-B-32"
|
||||||
|
pretrained: str = "laion2b_s34b_b79k"
|
||||||
|
device: str = "cpu"
|
||||||
|
batch_size: int = 64
|
||||||
|
normalize: bool = True
|
||||||
|
_model = PrivateAttr()
|
||||||
|
_preprocess = PrivateAttr()
|
||||||
|
_tokenizer = PrivateAttr()
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
open_clip = attempt_import_or_raise("open_clip", "open-clip") # EmbeddingFunction util to import external libs and raise if not found
|
||||||
|
model, _, preprocess = open_clip.create_model_and_transforms(
|
||||||
|
self.name, pretrained=self.pretrained
|
||||||
|
)
|
||||||
|
model.to(self.device)
|
||||||
|
self._model, self._preprocess = model, preprocess
|
||||||
|
self._tokenizer = open_clip.get_tokenizer(self.name)
|
||||||
|
self._ndims = None
|
||||||
|
|
||||||
|
def ndims(self):
|
||||||
|
if self._ndims is None:
|
||||||
|
self._ndims = self.generate_text_embeddings("foo").shape[0]
|
||||||
|
return self._ndims
|
||||||
|
|
||||||
|
def compute_query_embeddings(
|
||||||
|
self, query: Union[str, "PIL.Image.Image"], *args, **kwargs
|
||||||
|
) -> List[np.ndarray]:
|
||||||
|
"""
|
||||||
|
Compute the embeddings for a given user query
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
query : Union[str, PIL.Image.Image]
|
||||||
|
The query to embed. A query can be either text or an image.
|
||||||
|
"""
|
||||||
|
if isinstance(query, str):
|
||||||
|
return [self.generate_text_embeddings(query)]
|
||||||
|
else:
|
||||||
|
PIL = attempt_import_or_raise("PIL", "pillow")
|
||||||
|
if isinstance(query, PIL.Image.Image):
|
||||||
|
return [self.generate_image_embedding(query)]
|
||||||
|
else:
|
||||||
|
raise TypeError("OpenClip supports str or PIL Image as query")
|
||||||
|
|
||||||
|
def generate_text_embeddings(self, text: str) -> np.ndarray:
|
||||||
|
torch = attempt_import_or_raise("torch")
|
||||||
|
text = self.sanitize_input(text)
|
||||||
|
text = self._tokenizer(text)
|
||||||
|
text.to(self.device)
|
||||||
|
with torch.no_grad():
|
||||||
|
text_features = self._model.encode_text(text.to(self.device))
|
||||||
|
if self.normalize:
|
||||||
|
text_features /= text_features.norm(dim=-1, keepdim=True)
|
||||||
|
return text_features.cpu().numpy().squeeze()
|
||||||
|
|
||||||
|
def sanitize_input(self, images: IMAGES) -> Union[List[bytes], np.ndarray]:
|
||||||
|
"""
|
||||||
|
Sanitize the input to the embedding function.
|
||||||
|
"""
|
||||||
|
if isinstance(images, (str, bytes)):
|
||||||
|
images = [images]
|
||||||
|
elif isinstance(images, pa.Array):
|
||||||
|
images = images.to_pylist()
|
||||||
|
elif isinstance(images, pa.ChunkedArray):
|
||||||
|
images = images.combine_chunks().to_pylist()
|
||||||
|
return images
|
||||||
|
|
||||||
|
def compute_source_embeddings(
|
||||||
|
self, images: IMAGES, *args, **kwargs
|
||||||
|
) -> List[np.array]:
|
||||||
|
"""
|
||||||
|
Get the embeddings for the given images
|
||||||
|
"""
|
||||||
|
images = self.sanitize_input(images)
|
||||||
|
embeddings = []
|
||||||
|
for i in range(0, len(images), self.batch_size):
|
||||||
|
j = min(i + self.batch_size, len(images))
|
||||||
|
batch = images[i:j]
|
||||||
|
embeddings.extend(self._parallel_get(batch))
|
||||||
|
return embeddings
|
||||||
|
|
||||||
|
def _parallel_get(self, images: Union[List[str], List[bytes]]) -> List[np.ndarray]:
|
||||||
|
"""
|
||||||
|
Issue concurrent requests to retrieve the image data
|
||||||
|
"""
|
||||||
|
with concurrent.futures.ThreadPoolExecutor() as executor:
|
||||||
|
futures = [
|
||||||
|
executor.submit(self.generate_image_embedding, image)
|
||||||
|
for image in images
|
||||||
|
]
|
||||||
|
return [future.result() for future in futures]
|
||||||
|
|
||||||
|
def generate_image_embedding(
|
||||||
|
self, image: Union[str, bytes, "PIL.Image.Image"]
|
||||||
|
) -> np.ndarray:
|
||||||
|
"""
|
||||||
|
Generate the embedding for a single image
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
image : Union[str, bytes, PIL.Image.Image]
|
||||||
|
The image to embed. If the image is a str, it is treated as a uri.
|
||||||
|
If the image is bytes, it is treated as the raw image bytes.
|
||||||
|
"""
|
||||||
|
torch = attempt_import_or_raise("torch")
|
||||||
|
# TODO handle retry and errors for https
|
||||||
|
image = self._to_pil(image)
|
||||||
|
image = self._preprocess(image).unsqueeze(0)
|
||||||
|
with torch.no_grad():
|
||||||
|
return self._encode_and_normalize_image(image)
|
||||||
|
|
||||||
|
def _to_pil(self, image: Union[str, bytes]):
|
||||||
|
PIL = attempt_import_or_raise("PIL", "pillow")
|
||||||
|
if isinstance(image, bytes):
|
||||||
|
return PIL.Image.open(io.BytesIO(image))
|
||||||
|
if isinstance(image, PIL.Image.Image):
|
||||||
|
return image
|
||||||
|
elif isinstance(image, str):
|
||||||
|
parsed = urlparse.urlparse(image)
|
||||||
|
# TODO handle drive letter on windows.
|
||||||
|
if parsed.scheme == "file":
|
||||||
|
return PIL.Image.open(parsed.path)
|
||||||
|
elif parsed.scheme == "":
|
||||||
|
return PIL.Image.open(image if os.name == "nt" else parsed.path)
|
||||||
|
elif parsed.scheme.startswith("http"):
|
||||||
|
return PIL.Image.open(io.BytesIO(url_retrieve(image)))
|
||||||
|
else:
|
||||||
|
raise NotImplementedError("Only local and http(s) urls are supported")
|
||||||
|
|
||||||
|
def _encode_and_normalize_image(self, image_tensor: "torch.Tensor"):
|
||||||
|
"""
|
||||||
|
encode a single image tensor and optionally normalize the output
|
||||||
|
"""
|
||||||
|
image_features = self._model.encode_image(image_tensor)
|
||||||
|
if self.normalize:
|
||||||
|
image_features /= image_features.norm(dim=-1, keepdim=True)
|
||||||
|
return image_features.cpu().numpy().squeeze()
|
||||||
|
```
|
||||||
291
docs/src/embeddings/default_embedding_functions.md
Normal file
@@ -0,0 +1,291 @@
|
|||||||
|
There are various embedding functions available out of the box with LanceDB to manage your embeddings implicitly. We're actively working on adding other popular embedding APIs and models.
|
||||||
|
|
||||||
|
## Text embedding functions
|
||||||
|
Contains the text embedding functions registered by default.
|
||||||
|
|
||||||
|
* Embedding functions have an inbuilt rate limit handler wrapper for source and query embedding function calls that retry with exponential backoff.
|
||||||
|
* Each `EmbeddingFunction` implementation automatically takes `max_retries` as an argument which has the default value of 7.
|
||||||
|
|
||||||
|
### Sentence transformers
|
||||||
|
Allows you to set parameters when registering a `sentence-transformers` object.
|
||||||
|
|
||||||
|
!!! info
|
||||||
|
Sentence transformer embeddings are normalized by default. It is recommended to use normalized embeddings for similarity search.
|
||||||
|
|
||||||
|
| Parameter | Type | Default Value | Description |
|
||||||
|
|---|---|---|---|
|
||||||
|
| `name` | `str` | `all-MiniLM-L6-v2` | The name of the model |
|
||||||
|
| `device` | `str` | `cpu` | The device to run the model on (can be `cpu` or `gpu`) |
|
||||||
|
| `normalize` | `bool` | `True` | Whether to normalize the input text before feeding it to the model |
|
||||||
|
|
||||||
|
|
||||||
|
```python
|
||||||
|
db = lancedb.connect("/tmp/db")
|
||||||
|
registry = EmbeddingFunctionRegistry.get_instance()
|
||||||
|
func = registry.get("sentence-transformers").create(device="cpu")
|
||||||
|
|
||||||
|
class Words(LanceModel):
|
||||||
|
text: str = func.SourceField()
|
||||||
|
vector: Vector(func.ndims()) = func.VectorField()
|
||||||
|
|
||||||
|
table = db.create_table("words", schema=Words)
|
||||||
|
table.add(
|
||||||
|
[
|
||||||
|
{"text": "hello world"}
|
||||||
|
{"text": "goodbye world"}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
query = "greetings"
|
||||||
|
actual = table.search(query).limit(1).to_pydantic(Words)[0]
|
||||||
|
print(actual.text)
|
||||||
|
```
|
||||||
|
|
||||||
|
### OpenAI embeddings
|
||||||
|
LanceDB registers the OpenAI embeddings function in the registry by default, as `openai`. Below are the parameters that you can customize when creating the instances:
|
||||||
|
|
||||||
|
| Parameter | Type | Default Value | Description |
|
||||||
|
|---|---|---|---|
|
||||||
|
| `name` | `str` | `"text-embedding-ada-002"` | The name of the model. |
|
||||||
|
|
||||||
|
|
||||||
|
```python
|
||||||
|
db = lancedb.connect("/tmp/db")
|
||||||
|
registry = EmbeddingFunctionRegistry.get_instance()
|
||||||
|
func = registry.get("openai").create()
|
||||||
|
|
||||||
|
class Words(LanceModel):
|
||||||
|
text: str = func.SourceField()
|
||||||
|
vector: Vector(func.ndims()) = func.VectorField()
|
||||||
|
|
||||||
|
table = db.create_table("words", schema=Words)
|
||||||
|
table.add(
|
||||||
|
[
|
||||||
|
{"text": "hello world"}
|
||||||
|
{"text": "goodbye world"}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
query = "greetings"
|
||||||
|
actual = table.search(query).limit(1).to_pydantic(Words)[0]
|
||||||
|
print(actual.text)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Instructor Embeddings
|
||||||
|
[Instructor](https://instructor-embedding.github.io/) is an instruction-finetuned text embedding model that can generate text embeddings tailored to any task (e.g. classification, retrieval, clustering, text evaluation, etc.) and domains (e.g. science, finance, etc.) by simply providing the task instruction, without any finetuning.
|
||||||
|
|
||||||
|
If you want to calculate customized embeddings for specific sentences, you can follow the unified template to write instructions.
|
||||||
|
|
||||||
|
!!! info
|
||||||
|
Represent the `domain` `text_type` for `task_objective`:
|
||||||
|
|
||||||
|
* `domain` is optional, and it specifies the domain of the text, e.g. science, finance, medicine, etc.
|
||||||
|
* `text_type` is required, and it specifies the encoding unit, e.g. sentence, document, paragraph, etc.
|
||||||
|
* `task_objective` is optional, and it specifies the objective of embedding, e.g. retrieve a document, classify the sentence, etc.
|
||||||
|
|
||||||
|
More information about the model can be found at the [source URL](https://github.com/xlang-ai/instructor-embedding).
|
||||||
|
|
||||||
|
| Argument | Type | Default | Description |
|
||||||
|
|---|---|---|---|
|
||||||
|
| `name` | `str` | "hkunlp/instructor-base" | The name of the model to use |
|
||||||
|
| `batch_size` | `int` | `32` | The batch size to use when generating embeddings |
|
||||||
|
| `device` | `str` | `"cpu"` | The device to use when generating embeddings |
|
||||||
|
| `show_progress_bar` | `bool` | `True` | Whether to show a progress bar when generating embeddings |
|
||||||
|
| `normalize_embeddings` | `bool` | `True` | Whether to normalize the embeddings |
|
||||||
|
| `quantize` | `bool` | `False` | Whether to quantize the model |
|
||||||
|
| `source_instruction` | `str` | `"represent the docuement for retreival"` | The instruction for the source column |
|
||||||
|
| `query_instruction` | `str` | `"represent the document for retreiving the most similar documents"` | The instruction for the query |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
```python
|
||||||
|
import lancedb
|
||||||
|
from lancedb.pydantic import LanceModel, Vector
|
||||||
|
from lancedb.embeddings import get_registry, InstuctorEmbeddingFunction
|
||||||
|
|
||||||
|
instructor = get_registry().get("instructor").create(
|
||||||
|
source_instruction="represent the docuement for retreival",
|
||||||
|
query_instruction="represent the document for retreiving the most similar documents"
|
||||||
|
)
|
||||||
|
|
||||||
|
class Schema(LanceModel):
|
||||||
|
vector: Vector(instructor.ndims()) = instructor.VectorField()
|
||||||
|
text: str = instructor.SourceField()
|
||||||
|
|
||||||
|
db = lancedb.connect("~/.lancedb")
|
||||||
|
tbl = db.create_table("test", schema=Schema, mode="overwrite")
|
||||||
|
|
||||||
|
texts = [{"text": "Capitalism has been dominant in the Western world since the end of feudalism, but most feel[who?] that..."},
|
||||||
|
{"text": "The disparate impact theory is especially controversial under the Fair Housing Act because the Act..."},
|
||||||
|
{"text": "Disparate impact in United States labor law refers to practices in employment, housing, and other areas that.."}]
|
||||||
|
|
||||||
|
tbl.add(texts)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Gemini Embeddings
|
||||||
|
With Google's Gemini, you can represent text (words, sentences, and blocks of text) in a vectorized form, making it easier to compare and contrast embeddings. For example, two texts that share a similar subject matter or sentiment should have similar embeddings, which can be identified through mathematical comparison techniques such as cosine similarity. For more on how and why you should use embeddings, refer to the Embeddings guide.
|
||||||
|
The Gemini Embedding Model API supports various task types:
|
||||||
|
|
||||||
|
| Task Type | Description |
|
||||||
|
|-------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| "`retrieval_query`" | Specifies the given text is a query in a search/retrieval setting. |
|
||||||
|
| "`retrieval_document`" | Specifies the given text is a document in a search/retrieval setting. Using this task type requires a title but is automatically proided by Embeddings API |
|
||||||
|
| "`semantic_similarity`" | Specifies the given text will be used for Semantic Textual Similarity (STS). |
|
||||||
|
| "`classification`" | Specifies that the embeddings will be used for classification. |
|
||||||
|
| "`clusering`" | Specifies that the embeddings will be used for clustering. |
|
||||||
|
|
||||||
|
|
||||||
|
Usage Example:
|
||||||
|
|
||||||
|
```python
|
||||||
|
import lancedb
|
||||||
|
import pandas as pd
|
||||||
|
from lancedb.pydantic import LanceModel, Vector
|
||||||
|
from lancedb.embeddings import get_registry
|
||||||
|
|
||||||
|
|
||||||
|
model = get_registry().get("gemini-text").create()
|
||||||
|
|
||||||
|
class TextModel(LanceModel):
|
||||||
|
text: str = model.SourceField()
|
||||||
|
vector: Vector(model.ndims()) = model.VectorField()
|
||||||
|
|
||||||
|
df = pd.DataFrame({"text": ["hello world", "goodbye world"]})
|
||||||
|
db = lancedb.connect("~/.lancedb")
|
||||||
|
tbl = db.create_table("test", schema=TextModel, mode="overwrite")
|
||||||
|
|
||||||
|
tbl.add(df)
|
||||||
|
rs = tbl.search("hello").limit(1).to_pandas()
|
||||||
|
```
|
||||||
|
|
||||||
|
### AWS Bedrock Text Embedding Functions
|
||||||
|
AWS Bedrock supports multiple base models for generating text embeddings. You need to setup the AWS credentials to use this embedding function.
|
||||||
|
You can do so by using `awscli` and also add your session_token:
|
||||||
|
```shell
|
||||||
|
aws configure
|
||||||
|
aws configure set aws_session_token "<your_session_token>"
|
||||||
|
```
|
||||||
|
to ensure that the credentials are set up correctly, you can run the following command:
|
||||||
|
```shell
|
||||||
|
aws sts get-caller-identity
|
||||||
|
```
|
||||||
|
|
||||||
|
Supported Embedding modelIDs are:
|
||||||
|
* `amazon.titan-embed-text-v1`
|
||||||
|
* `cohere.embed-english-v3`
|
||||||
|
* `cohere.embed-multilingual-v3`
|
||||||
|
|
||||||
|
Supported paramters (to be passed in `create` method) are:
|
||||||
|
| Parameter | Type | Default Value | Description |
|
||||||
|
|---|---|---|---|
|
||||||
|
| **name** | str | "amazon.titan-embed-text-v1" | The model ID of the bedrock model to use. Supported base models for Text Embeddings: amazon.titan-embed-text-v1, cohere.embed-english-v3, cohere.embed-multilingual-v3 |
|
||||||
|
| **region** | str | "us-east-1" | Optional name of the AWS Region in which the service should be called (e.g., "us-east-1"). |
|
||||||
|
| **profile_name** | str | None | Optional name of the AWS profile to use for calling the Bedrock service. If not specified, the default profile will be used. |
|
||||||
|
| **assumed_role** | str | None | Optional ARN of an AWS IAM role to assume for calling the Bedrock service. If not specified, the current active credentials will be used. |
|
||||||
|
| **role_session_name** | str | "lancedb-embeddings" | Optional name of the AWS IAM role session to use for calling the Bedrock service. If not specified, a "lancedb-embeddings" name will be used. |
|
||||||
|
| **runtime** | bool | True | Optional choice of getting different client to perform operations with the Amazon Bedrock service. |
|
||||||
|
| **max_retries** | int | 7 | Optional number of retries to perform when a request fails. |
|
||||||
|
|
||||||
|
Usage Example:
|
||||||
|
|
||||||
|
```python
|
||||||
|
model = get_registry().get("bedrock-text").create()
|
||||||
|
|
||||||
|
class TextModel(LanceModel):
|
||||||
|
text: str = model.SourceField()
|
||||||
|
vector: Vector(model.ndims()) = model.VectorField()
|
||||||
|
|
||||||
|
df = pd.DataFrame({"text": ["hello world", "goodbye world"]})
|
||||||
|
db = lancedb.connect("tmp_path")
|
||||||
|
tbl = db.create_table("test", schema=TextModel, mode="overwrite")
|
||||||
|
|
||||||
|
tbl.add(df)
|
||||||
|
rs = tbl.search("hello").limit(1).to_pandas()
|
||||||
|
```
|
||||||
|
|
||||||
|
## Multi-modal embedding functions
|
||||||
|
Multi-modal embedding functions allow you to query your table using both images and text.
|
||||||
|
|
||||||
|
### OpenClip embeddings
|
||||||
|
We support CLIP model embeddings using the open source alternative, [open-clip](https://github.com/mlfoundations/open_clip) which supports various customizations. It is registered as `open-clip` and supports the following customizations:
|
||||||
|
|
||||||
|
| Parameter | Type | Default Value | Description |
|
||||||
|
|---|---|---|---|
|
||||||
|
| `name` | `str` | `"ViT-B-32"` | The name of the model. |
|
||||||
|
| `pretrained` | `str` | `"laion2b_s34b_b79k"` | The name of the pretrained model to load. |
|
||||||
|
| `device` | `str` | `"cpu"` | The device to run the model on. Can be `"cpu"` or `"gpu"`. |
|
||||||
|
| `batch_size` | `int` | `64` | The number of images to process in a batch. |
|
||||||
|
| `normalize` | `bool` | `True` | Whether to normalize the input images before feeding them to the model. |
|
||||||
|
|
||||||
|
This embedding function supports ingesting images as both bytes and urls. You can query them using both test and other images.
|
||||||
|
|
||||||
|
!!! info
|
||||||
|
LanceDB supports ingesting images directly from accessible links.
|
||||||
|
|
||||||
|
|
||||||
|
```python
|
||||||
|
|
||||||
|
db = lancedb.connect(tmp_path)
|
||||||
|
registry = EmbeddingFunctionRegistry.get_instance()
|
||||||
|
func = registry.get("open-clip").create()
|
||||||
|
|
||||||
|
class Images(LanceModel):
|
||||||
|
label: str
|
||||||
|
image_uri: str = func.SourceField() # image uri as the source
|
||||||
|
image_bytes: bytes = func.SourceField() # image bytes as the source
|
||||||
|
vector: Vector(func.ndims()) = func.VectorField() # vector column
|
||||||
|
vec_from_bytes: Vector(func.ndims()) = func.VectorField() # Another vector column
|
||||||
|
|
||||||
|
table = db.create_table("images", schema=Images)
|
||||||
|
labels = ["cat", "cat", "dog", "dog", "horse", "horse"]
|
||||||
|
uris = [
|
||||||
|
"http://farm1.staticflickr.com/53/167798175_7c7845bbbd_z.jpg",
|
||||||
|
"http://farm1.staticflickr.com/134/332220238_da527d8140_z.jpg",
|
||||||
|
"http://farm9.staticflickr.com/8387/8602747737_2e5c2a45d4_z.jpg",
|
||||||
|
"http://farm5.staticflickr.com/4092/5017326486_1f46057f5f_z.jpg",
|
||||||
|
"http://farm9.staticflickr.com/8216/8434969557_d37882c42d_z.jpg",
|
||||||
|
"http://farm6.staticflickr.com/5142/5835678453_4f3a4edb45_z.jpg",
|
||||||
|
]
|
||||||
|
# get each uri as bytes
|
||||||
|
image_bytes = [requests.get(uri).content for uri in uris]
|
||||||
|
table.add(
|
||||||
|
[{"label": labels, "image_uri": uris, "image_bytes": image_bytes}]
|
||||||
|
)
|
||||||
|
```
|
||||||
|
Now we can search using text from both the default vector column and the custom vector column
|
||||||
|
```python
|
||||||
|
|
||||||
|
# text search
|
||||||
|
actual = table.search("man's best friend").limit(1).to_pydantic(Images)[0]
|
||||||
|
print(actual.label) # prints "dog"
|
||||||
|
|
||||||
|
frombytes = (
|
||||||
|
table.search("man's best friend", vector_column_name="vec_from_bytes")
|
||||||
|
.limit(1)
|
||||||
|
.to_pydantic(Images)[0]
|
||||||
|
)
|
||||||
|
print(frombytes.label)
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Because we're using a multi-modal embedding function, we can also search using images
|
||||||
|
|
||||||
|
```python
|
||||||
|
# image search
|
||||||
|
query_image_uri = "http://farm1.staticflickr.com/200/467715466_ed4a31801f_z.jpg"
|
||||||
|
image_bytes = requests.get(query_image_uri).content
|
||||||
|
query_image = Image.open(io.BytesIO(image_bytes))
|
||||||
|
actual = table.search(query_image).limit(1).to_pydantic(Images)[0]
|
||||||
|
print(actual.label == "dog")
|
||||||
|
|
||||||
|
# image search using a custom vector column
|
||||||
|
other = (
|
||||||
|
table.search(query_image, vector_column_name="vec_from_bytes")
|
||||||
|
.limit(1)
|
||||||
|
.to_pydantic(Images)[0]
|
||||||
|
)
|
||||||
|
print(actual.label)
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
If you have any questions about the embeddings API, supported models, or see a relevant model missing, please raise an issue [on GitHub](https://github.com/lancedb/lancedb/issues).
|
||||||
141
docs/src/embeddings/embedding_explicit.md
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
In this workflow, you define your own embedding function and pass it as a callable to LanceDB, invoking it in your code to generate the embeddings. Let's look at some examples.
|
||||||
|
|
||||||
|
### Hugging Face
|
||||||
|
|
||||||
|
!!! note
|
||||||
|
Currently, the Hugging Face method is only supported in the Python SDK.
|
||||||
|
|
||||||
|
=== "Python"
|
||||||
|
The most popular open source option is to use the [sentence-transformers](https://www.sbert.net/)
|
||||||
|
library, which can be installed via pip.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install sentence-transformers
|
||||||
|
```
|
||||||
|
|
||||||
|
The example below shows how to use the `paraphrase-albert-small-v2` model to generate embeddings
|
||||||
|
for a given document.
|
||||||
|
|
||||||
|
```python
|
||||||
|
from sentence_transformers import SentenceTransformer
|
||||||
|
|
||||||
|
name="paraphrase-albert-small-v2"
|
||||||
|
model = SentenceTransformer(name)
|
||||||
|
|
||||||
|
# used for both training and querying
|
||||||
|
def embed_func(batch):
|
||||||
|
return [model.encode(sentence) for sentence in batch]
|
||||||
|
```
|
||||||
|
|
||||||
|
### OpenAI
|
||||||
|
|
||||||
|
Another popular alternative is to use an external API like OpenAI's [embeddings API](https://platform.openai.com/docs/guides/embeddings/what-are-embeddings).
|
||||||
|
|
||||||
|
=== "Python"
|
||||||
|
```python
|
||||||
|
import openai
|
||||||
|
import os
|
||||||
|
|
||||||
|
# Configuring the environment variable OPENAI_API_KEY
|
||||||
|
if "OPENAI_API_KEY" not in os.environ:
|
||||||
|
# OR set the key here as a variable
|
||||||
|
openai.api_key = "sk-..."
|
||||||
|
|
||||||
|
# verify that the API key is working
|
||||||
|
assert len(openai.Model.list()["data"]) > 0
|
||||||
|
|
||||||
|
def embed_func(c):
|
||||||
|
rs = openai.Embedding.create(input=c, engine="text-embedding-ada-002")
|
||||||
|
return [record["embedding"] for record in rs["data"]]
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "JavaScript"
|
||||||
|
```javascript
|
||||||
|
const lancedb = require("vectordb");
|
||||||
|
|
||||||
|
// You need to provide an OpenAI API key
|
||||||
|
const apiKey = "sk-..."
|
||||||
|
// The embedding function will create embeddings for the 'text' column
|
||||||
|
const embedding = new lancedb.OpenAIEmbeddingFunction('text', apiKey)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Applying an embedding function to data
|
||||||
|
|
||||||
|
=== "Python"
|
||||||
|
Using an embedding function, you can apply it to raw data
|
||||||
|
to generate embeddings for each record.
|
||||||
|
|
||||||
|
Say you have a pandas DataFrame with a `text` column that you want embedded,
|
||||||
|
you can use the `with_embeddings` function to generate embeddings and add them to
|
||||||
|
an existing table.
|
||||||
|
|
||||||
|
```python
|
||||||
|
import pandas as pd
|
||||||
|
from lancedb.embeddings import with_embeddings
|
||||||
|
|
||||||
|
df = pd.DataFrame(
|
||||||
|
[
|
||||||
|
{"text": "pepperoni"},
|
||||||
|
{"text": "pineapple"}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
data = with_embeddings(embed_func, df)
|
||||||
|
|
||||||
|
# The output is used to create / append to a table
|
||||||
|
# db.create_table("my_table", data=data)
|
||||||
|
```
|
||||||
|
|
||||||
|
If your data is in a different column, you can specify the `column` kwarg to `with_embeddings`.
|
||||||
|
|
||||||
|
By default, LanceDB calls the function with batches of 1000 rows. This can be configured
|
||||||
|
using the `batch_size` parameter to `with_embeddings`.
|
||||||
|
|
||||||
|
LanceDB automatically wraps the function with retry and rate-limit logic to ensure the OpenAI
|
||||||
|
API call is reliable.
|
||||||
|
|
||||||
|
=== "JavaScript"
|
||||||
|
Using an embedding function, you can apply it to raw data
|
||||||
|
to generate embeddings for each record.
|
||||||
|
|
||||||
|
Simply pass the embedding function created above and LanceDB will use it to generate
|
||||||
|
embeddings for your data.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const db = await lancedb.connect("data/sample-lancedb");
|
||||||
|
const data = [
|
||||||
|
{ text: "pepperoni"},
|
||||||
|
{ text: "pineapple"}
|
||||||
|
]
|
||||||
|
|
||||||
|
const table = await db.createTable("vectors", data, embedding)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Querying using an embedding function
|
||||||
|
|
||||||
|
!!! warning
|
||||||
|
At query time, you **must** use the same embedding function you used to vectorize your data.
|
||||||
|
If you use a different embedding function, the embeddings will not reside in the same vector
|
||||||
|
space and the results will be nonsensical.
|
||||||
|
|
||||||
|
=== "Python"
|
||||||
|
```python
|
||||||
|
query = "What's the best pizza topping?"
|
||||||
|
query_vector = embed_func([query])[0]
|
||||||
|
results = (
|
||||||
|
tbl.search(query_vector)
|
||||||
|
.limit(10)
|
||||||
|
.to_pandas()
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
The above snippet returns a pandas DataFrame with the 10 closest vectors to the query.
|
||||||
|
|
||||||
|
=== "JavaScript"
|
||||||
|
```javascript
|
||||||
|
const results = await table
|
||||||
|
.search("What's the best pizza topping?")
|
||||||
|
.limit(10)
|
||||||
|
.execute()
|
||||||
|
```
|
||||||
|
|
||||||
|
The above snippet returns an array of records with the top 10 nearest neighbors to the query.
|
||||||
103
docs/src/embeddings/embedding_functions.md
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
Representing multi-modal data as vector embeddings is becoming a standard practice. Embedding functions can themselves be thought of as key part of the data processing pipeline that each request has to be passed through. The assumption here is: after initial setup, these components and the underlying methodology are not expected to change for a particular project.
|
||||||
|
|
||||||
|
For this purpose, LanceDB introduces an **embedding functions API**, that allow you simply set up once, during the configuration stage of your project. After this, the table remembers it, effectively making the embedding functions *disappear in the background* so you don't have to worry about manually passing callables, and instead, simply focus on the rest of your data engineering pipeline.
|
||||||
|
|
||||||
|
!!! warning
|
||||||
|
Using the implicit embeddings management approach means that you can forget about the manually passing around embedding
|
||||||
|
functions in your code, as long as you don't intend to change it at a later time. If your embedding function changes,
|
||||||
|
you'll have to re-configure your table with the new embedding function and regenerate the embeddings.
|
||||||
|
|
||||||
|
## 1. Define the embedding function
|
||||||
|
We have some pre-defined embedding functions in the global registry, with more coming soon. Here's let's an implementation of CLIP as example.
|
||||||
|
```
|
||||||
|
registry = EmbeddingFunctionRegistry.get_instance()
|
||||||
|
clip = registry.get("open-clip").create()
|
||||||
|
|
||||||
|
```
|
||||||
|
You can also define your own embedding function by implementing the `EmbeddingFunction` abstract base interface. It subclasses Pydantic Model which can be utilized to write complex schemas simply as we'll see next!
|
||||||
|
|
||||||
|
## 2. Define the data model or schema
|
||||||
|
The embedding function defined above abstracts away all the details about the models and dimensions required to define the schema. You can simply set a field as **source** or **vector** column. Here's how:
|
||||||
|
|
||||||
|
```python
|
||||||
|
class Pets(LanceModel):
|
||||||
|
vector: Vector(clip.ndims) = clip.VectorField()
|
||||||
|
image_uri: str = clip.SourceField()
|
||||||
|
```
|
||||||
|
|
||||||
|
`VectorField` tells LanceDB to use the clip embedding function to generate query embeddings for the `vector` column and `SourceField` ensures that when adding data, we automatically use the specified embedding function to encode `image_uri`.
|
||||||
|
|
||||||
|
## 3. Create LanceDB table
|
||||||
|
Now that we have chosen/defined our embedding function and the schema, we can create the table:
|
||||||
|
|
||||||
|
```python
|
||||||
|
db = lancedb.connect("~/lancedb")
|
||||||
|
table = db.create_table("pets", schema=Pets)
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
That's it! We've provided all the information needed to embed the source and query inputs. We can now forget about the model and dimension details and start to build our VectorDB pipeline.
|
||||||
|
|
||||||
|
## 4. Ingest lots of data and query your table
|
||||||
|
Any new or incoming data can just be added and it'll be vectorized automatically.
|
||||||
|
|
||||||
|
```python
|
||||||
|
table.add([{"image_uri": u} for u in uris])
|
||||||
|
```
|
||||||
|
|
||||||
|
Our OpenCLIP query embedding function supports querying via both text and images:
|
||||||
|
|
||||||
|
```python
|
||||||
|
result = table.search("dog")
|
||||||
|
```
|
||||||
|
|
||||||
|
Let's query an image:
|
||||||
|
|
||||||
|
```python
|
||||||
|
p = Path("path/to/images/samoyed_100.jpg")
|
||||||
|
query_image = Image.open(p)
|
||||||
|
table.search(query_image)
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Rate limit Handling
|
||||||
|
`EmbeddingFunction` class wraps the calls for source and query embedding generation inside a rate limit handler that retries the requests with exponential backoff after successive failures. By default, the maximum retires is set to 7. You can tune it by setting it to a different number, or disable it by setting it to 0.
|
||||||
|
|
||||||
|
An example of how to do this is shown below:
|
||||||
|
|
||||||
|
```python
|
||||||
|
clip = registry.get("open-clip").create() # Defaults to 7 max retries
|
||||||
|
clip = registry.get("open-clip").create(max_retries=10) # Increase max retries to 10
|
||||||
|
clip = registry.get("open-clip").create(max_retries=0) # Retries disabled
|
||||||
|
```
|
||||||
|
|
||||||
|
!!! note
|
||||||
|
Embedding functions can also fail due to other errors that have nothing to do with rate limits.
|
||||||
|
This is why the error is also logged.
|
||||||
|
|
||||||
|
## Some fun with Pydantic
|
||||||
|
|
||||||
|
LanceDB is integrated with Pydantic, which was used in the example above to define the schema in Python. It's also used behind the scenes by the embedding function API to ingest useful information as table metadata.
|
||||||
|
|
||||||
|
You can also use the integration for adding utility operations in the schema. For example, in our multi-modal example, you can search images using text or another image. Let's define a utility function to plot the image.
|
||||||
|
|
||||||
|
```python
|
||||||
|
class Pets(LanceModel):
|
||||||
|
vector: Vector(clip.ndims) = clip.VectorField()
|
||||||
|
image_uri: str = clip.SourceField()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def image(self):
|
||||||
|
return Image.open(self.image_uri)
|
||||||
|
```
|
||||||
|
Now, you can covert your search results to a Pydantic model and use this property.
|
||||||
|
|
||||||
|
```python
|
||||||
|
rs = table.search(query_image).limit(3).to_pydantic(Pets)
|
||||||
|
rs[2].image
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Now that you have the basic idea about implicit management via embedding functions, let's dive deeper into a [custom API](./api.md) that you can use to implement your own embedding functions.
|
||||||
8
docs/src/embeddings/index.md
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
Due to the nature of vector embeddings, they can be used to represent any kind of data, from text to images to audio. This makes them a very powerful tool for machine learning practitioners. However, there's no one-size-fits-all solution for generating embeddings - there are many different libraries and APIs (both commercial and open source) that can be used to generate embeddings from structured/unstructured data.
|
||||||
|
|
||||||
|
LanceDB supports 2 methods of vectorizing your raw data into embeddings.
|
||||||
|
|
||||||
|
1. **Explicit**: By manually calling LanceDB's `with_embedding` function to vectorize your data via an `embed_func` of your choice
|
||||||
|
2. **Implicit**: Allow LanceDB to embed the data and queries in the background as they come in, by using the table's `EmbeddingRegistry` information
|
||||||
|
|
||||||
|
See the [explicit](embedding_explicit.md) and [implicit](embedding_functions.md) embedding sections for more details.
|
||||||
11
docs/src/examples/examples_js.md
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# Examples: JavaScript
|
||||||
|
|
||||||
|
To help you get started, we provide some examples, projects and applications that use the LanceDB JavaScript API. You can always find the latest examples in our [VectorDB Recipes](https://github.com/lancedb/vectordb-recipes) repository.
|
||||||
|
|
||||||
|
| Example | Scripts |
|
||||||
|
|-------- | ------ |
|
||||||
|
| | |
|
||||||
|
| [Youtube transcript search bot](https://github.com/lancedb/vectordb-recipes/tree/main/examples/youtube_bot/) | [](https://github.com/lancedb/vectordb-recipes/tree/main/examples/youtube_bot/index.js)|
|
||||||
|
| [Langchain: Code Docs QA bot](https://github.com/lancedb/vectordb-recipes/tree/main/examples/Code-Documentation-QA-Bot/) | [](https://github.com/lancedb/vectordb-recipes/tree/main/examples/Code-Documentation-QA-Bot/index.js)|
|
||||||
|
| [AI Agents: Reducing Hallucination](https://github.com/lancedb/vectordb-recipes/tree/main/examples/reducing_hallucinations_ai_agents/) | [](https://github.com/lancedb/vectordb-recipes/tree/main/examples/reducing_hallucinations_ai_agents/index.js)|
|
||||||
|
| [TransformersJS Embedding example](https://github.com/lancedb/vectordb-recipes/tree/main/examples/js-transformers/) | [](https://github.com/lancedb/vectordb-recipes/tree/main/examples/js-transformers/index.js) |
|
||||||
17
docs/src/examples/examples_python.md
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
# Examples: Python
|
||||||
|
|
||||||
|
To help you get started, we provide some examples, projects and applications that use the LanceDB Python API. You can always find the latest examples in our [VectorDB Recipes](https://github.com/lancedb/vectordb-recipes) repository.
|
||||||
|
|
||||||
|
| Example | Interactive Envs | Scripts |
|
||||||
|
|-------- | ---------------- | ------ |
|
||||||
|
| | | |
|
||||||
|
| [Youtube transcript search bot](https://github.com/lancedb/vectordb-recipes/tree/main/examples/youtube_bot/) | <a href="https://colab.research.google.com/github/lancedb/vectordb-recipes/blob/main/examples/youtube_bot/main.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"></a>| [](https://github.com/lancedb/vectordb-recipes/tree/main/examples/youtube_bot/main.py)|
|
||||||
|
| [Langchain: Code Docs QA bot](https://github.com/lancedb/vectordb-recipes/tree/main/examples/Code-Documentation-QA-Bot/) | <a href="https://colab.research.google.com/github/lancedb/vectordb-recipes/blob/main/examples/Code-Documentation-QA-Bot/main.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"></a>| [](https://github.com/lancedb/vectordb-recipes/tree/main/examples/Code-Documentation-QA-Bot/main.py) |
|
||||||
|
| [AI Agents: Reducing Hallucination](https://github.com/lancedb/vectordb-recipes/tree/main/examples/reducing_hallucinations_ai_agents/) | <a href="https://colab.research.google.com/github/lancedb/vectordb-recipes/blob/main/examples/reducing_hallucinations_ai_agents/main.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"></a>| [](https://github.com/lancedb/vectordb-recipes/tree/main/examples/reducing_hallucinations_ai_agents/main.py)|
|
||||||
|
| [Multimodal CLIP: DiffusionDB](https://github.com/lancedb/vectordb-recipes/tree/main/examples/multimodal_clip/) | <a href="https://colab.research.google.com/github/lancedb/vectordb-recipes/blob/main/examples/multimodal_clip/main.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"></a>| [](https://github.com/lancedb/vectordb-recipes/tree/main/examples/multimodal_clip/main.py) |
|
||||||
|
| [Multimodal CLIP: Youtube videos](https://github.com/lancedb/vectordb-recipes/tree/main/examples/multimodal_video_search/) | <a href="https://colab.research.google.com/github/lancedb/vectordb-recipes/blob/main/examples/multimodal_video_search/main.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"></a>| [](https://github.com/lancedb/vectordb-recipes/tree/main/examples/multimodal_video_search/main.py) |
|
||||||
|
| [Movie Recommender](https://github.com/lancedb/vectordb-recipes/tree/main/examples/movie-recommender/) | <a href="https://colab.research.google.com/github/lancedb/vectordb-recipes/blob/main/examples/movie-recommender/main.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"></a> | [](https://github.com/lancedb/vectordb-recipes/tree/main/examples/movie-recommender/main.py) |
|
||||||
|
| [Audio Search](https://github.com/lancedb/vectordb-recipes/tree/main/examples/audio_search/) | <a href="https://colab.research.google.com/github/lancedb/vectordb-recipes/blob/main/examples/audio_search/main.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"></a> | [](https://github.com/lancedb/vectordb-recipes/tree/main/examples/audio_search/main.py) |
|
||||||
|
| [Multimodal Image + Text Search](https://github.com/lancedb/vectordb-recipes/tree/main/examples/multimodal_search/) | <a href="https://colab.research.google.com/github/lancedb/vectordb-recipes/blob/main/examples/multimodal_search/main.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"></a> | [](https://github.com/lancedb/vectordb-recipes/tree/main/examples/multimodal_search/main.py) |
|
||||||
|
| [Evaluating Prompts with Prompttools](https://github.com/lancedb/vectordb-recipes/tree/main/examples/prompttools-eval-prompts/) | <a href="https://colab.research.google.com/github/lancedb/vectordb-recipes/blob/main/examples/prompttools-eval-prompts/main.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"></a> | |
|
||||||
|
|
||||||
165
docs/src/examples/image_embeddings_roboflow.md
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
# How to Load Image Embeddings into LanceDB
|
||||||
|
|
||||||
|
With the rise of Large Multimodal Models (LMMs) such as [GPT-4 Vision](https://blog.roboflow.com/gpt-4-vision/), the need for storing image embeddings is growing. The most effective way to store text and image embeddings is in a vector database such as LanceDB. Vector databases are a special kind of data store that enables efficient search over stored embeddings.
|
||||||
|
|
||||||
|
[CLIP](https://blog.roboflow.com/openai-clip/), a multimodal model developed by OpenAI, is commonly used to calculate image embeddings. These embeddings can then be used with a vector database to build a semantic search engine that you can query using images or text. For example, you could use LanceDB and CLIP embeddings to build a search engine for a database of folders.
|
||||||
|
|
||||||
|
In this guide, we are going to show you how to use Roboflow Inference to load image embeddings into LanceDB. Without further ado, let’s get started!
|
||||||
|
|
||||||
|
## Step #1: Install Roboflow Inference
|
||||||
|
|
||||||
|
[Roboflow Inference](https://inference.roboflow.com) enables you to run state-of-the-art computer vision models with minimal configuration. Inference supports a range of models, from fine-tuned object detection, classification, and segmentation models to foundation models like CLIP. We will use Inference to calculate CLIP image embeddings.
|
||||||
|
|
||||||
|
Inference provides a HTTP API through which you can run vision models.
|
||||||
|
|
||||||
|
Inference powers the Roboflow hosted API, and is available as an open source utility. In this guide, we are going to run Inference locally, which enables you to calculate CLIP embeddings on your own hardware. We will also show you how to use the hosted Roboflow CLIP API, which is ideal if you need to scale and do not want to manage a system for calculating embeddings.
|
||||||
|
|
||||||
|
To get started, first install the Inference CLI:
|
||||||
|
|
||||||
|
```
|
||||||
|
pip install inference-cli
|
||||||
|
```
|
||||||
|
|
||||||
|
Next, install Docker. Refer to the official Docker installation instructions for your operating system to get Docker set up. Once Docker is ready, you can start Inference using the following command:
|
||||||
|
|
||||||
|
```
|
||||||
|
inference server start
|
||||||
|
```
|
||||||
|
|
||||||
|
An Inference server will start running at ‘http://localhost:9001’.
|
||||||
|
|
||||||
|
## Step #2: Set Up a LanceDB Vector Database
|
||||||
|
|
||||||
|
Now that we have Inference running, we can set up a LanceDB vector database. You can run LanceDB in JavaScript and Python. For this guide, we will use the Python API. But, you can take the HTTP requests we make below and change them to JavaScript if required.
|
||||||
|
|
||||||
|
For this guide, we are going to search the [COCO 128 dataset](https://universe.roboflow.com/team-roboflow/coco-128), which contains a wide range of objects. The variability in objects present in this dataset makes it a good dataset to demonstrate the capabilities of vector search. If you want to use this dataset, you can download [COCO 128 from Roboflow Universe](https://universe.roboflow.com/team-roboflow/coco-128). With that said, you can search whatever folder of images you want.
|
||||||
|
|
||||||
|
Once you have a dataset ready, install LanceDB with the following command:
|
||||||
|
|
||||||
|
```
|
||||||
|
pip install lancedb
|
||||||
|
```
|
||||||
|
|
||||||
|
We also need to install a specific commit of `tantivy`, a dependency of the LanceDB full text search engine we will use later in this guide:
|
||||||
|
|
||||||
|
```
|
||||||
|
pip install tantivy@git+https://github.com/quickwit-oss/tantivy-py#164adc87e1a033117001cf70e38c82a53014d985
|
||||||
|
```
|
||||||
|
|
||||||
|
Create a new Python file and add the following code:
|
||||||
|
|
||||||
|
```python
|
||||||
|
import cv2
|
||||||
|
import supervision as sv
|
||||||
|
import requests
|
||||||
|
|
||||||
|
import lancedb
|
||||||
|
|
||||||
|
db = lancedb.connect("./embeddings")
|
||||||
|
|
||||||
|
IMAGE_DIR = "images/"
|
||||||
|
API_KEY = os.environ.get("ROBOFLOW_API_KEY")
|
||||||
|
SERVER_URL = "http://localhost:9001"
|
||||||
|
|
||||||
|
results = []
|
||||||
|
|
||||||
|
for i, image in enumerate(os.listdir(IMAGE_DIR)):
|
||||||
|
infer_clip_payload = {
|
||||||
|
#Images can be provided as urls or as base64 encoded strings
|
||||||
|
"image": {
|
||||||
|
"type": "base64",
|
||||||
|
"value": base64.b64encode(open(IMAGE_DIR + image, "rb").read()).decode("utf-8"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
res = requests.post(
|
||||||
|
f"{SERVER_URL}/clip/embed_image?api_key={API_KEY}",
|
||||||
|
json=infer_clip_payload,
|
||||||
|
)
|
||||||
|
|
||||||
|
embeddings = res.json()['embeddings']
|
||||||
|
|
||||||
|
print("Calculated embedding for image: ", image)
|
||||||
|
|
||||||
|
image = {"vector": embeddings[0], "name": os.path.join(IMAGE_DIR, image)}
|
||||||
|
|
||||||
|
results.append(image)
|
||||||
|
|
||||||
|
tbl = db.create_table("images", data=results)
|
||||||
|
|
||||||
|
tbl.create_fts_index("name")
|
||||||
|
```
|
||||||
|
|
||||||
|
To use the code above, you will need a Roboflow API key. [Learn how to retrieve a Roboflow API key](https://docs.roboflow.com/api-reference/authentication#retrieve-an-api-key). Run the following command to set up your API key in your environment:
|
||||||
|
|
||||||
|
```
|
||||||
|
export ROBOFLOW_API_KEY=""
|
||||||
|
```
|
||||||
|
|
||||||
|
Replace the `IMAGE_DIR` value with the folder in which you are storing the images for which you want to calculate embeddings. If you want to use the Roboflow CLIP API to calculate embeddings, replace the `SERVER_URL` value with `https://infer.roboflow.com`.
|
||||||
|
|
||||||
|
Run the script above to create a new LanceDB database. This database will be stored on your local machine. The database will be called `embeddings` and the table will be called `images`.
|
||||||
|
|
||||||
|
The script above calculates all embeddings for a folder then creates a new table. To add additional images, use the following code:
|
||||||
|
|
||||||
|
```python
|
||||||
|
def make_batches():
|
||||||
|
for i in range(5):
|
||||||
|
yield [
|
||||||
|
{"vector": [3.1, 4.1], "name": "image1.png"},
|
||||||
|
{"vector": [5.9, 26.5], "name": "image2.png"}
|
||||||
|
]
|
||||||
|
|
||||||
|
tbl = db.open_table("images")
|
||||||
|
tbl.add(make_batches())
|
||||||
|
```
|
||||||
|
|
||||||
|
Replacing the `make_batches()` function with code to load embeddings for images.
|
||||||
|
|
||||||
|
## Step #3: Run a Search Query
|
||||||
|
|
||||||
|
We are now ready to run a search query. To run a search query, we need a text embedding that represents a text query. We can use this embedding to search our LanceDB database for an entry.
|
||||||
|
|
||||||
|
Let’s calculate a text embedding for the query “cat”, then run a search query:
|
||||||
|
|
||||||
|
```python
|
||||||
|
infer_clip_payload = {
|
||||||
|
"text": "cat",
|
||||||
|
}
|
||||||
|
|
||||||
|
res = requests.post(
|
||||||
|
f"{SERVER_URL}/clip/embed_text?api_key={API_KEY}",
|
||||||
|
json=infer_clip_payload,
|
||||||
|
)
|
||||||
|
|
||||||
|
embeddings = res.json()['embeddings']
|
||||||
|
|
||||||
|
df = tbl.search(embeddings[0]).limit(3).to_list()
|
||||||
|
|
||||||
|
print("Results:")
|
||||||
|
|
||||||
|
for i in df:
|
||||||
|
print(i["name"])
|
||||||
|
```
|
||||||
|
|
||||||
|
This code will search for the three images most closely related to the prompt “cat”. The names of the most similar three images will be printed to the console. Here are the three top results:
|
||||||
|
|
||||||
|
```
|
||||||
|
dataset/images/train/000000000650_jpg.rf.1b74ba165c5a3513a3211d4a80b69e1c.jpg
|
||||||
|
dataset/images/train/000000000138_jpg.rf.af439ef1c55dd8a4e4b142d186b9c957.jpg
|
||||||
|
dataset/images/train/000000000165_jpg.rf.eae14d5509bf0c9ceccddbb53a5f0c66.jpg
|
||||||
|
```
|
||||||
|
|
||||||
|
Let’s open the top image:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
The top image was a cat. Our search was successful.
|
||||||
|
|
||||||
|
## Conclusion
|
||||||
|
|
||||||
|
LanceDB is a vector database that you can use to store and efficiently search your image embeddings. You can use Roboflow Inference, a scalable computer vision inference server, to calculate CLIP embeddings that you can store in LanceDB.
|
||||||
|
|
||||||
|
You can use Inference and LanceDB together to build a range of applications with image embeddings, from a media search engine to a retrieval-augmented generation pipeline for use with LMMs.
|
||||||
|
|
||||||
|
To learn more about Inference and its capabilities, refer to the Inference documentation.
|
||||||
15
docs/src/examples/index.md
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# Example projects and recipes
|
||||||
|
|
||||||
|
## Recipes and example code
|
||||||
|
|
||||||
|
LanceDB provides language APIs, allowing you to embed a database in your language of choice. We currently provide Python and Javascript APIs, with the Rust API and examples actively being worked on and will be available soon.
|
||||||
|
|
||||||
|
* 🐍 [Python](examples_python.md) examples
|
||||||
|
* 👾 [JavaScript](exampled_js.md) examples
|
||||||
|
|
||||||
|
## Applications powered by LanceDB
|
||||||
|
|
||||||
|
| Project Name | Description | Screenshot |
|
||||||
|
|-----------------------------------------------------|----------------------------------------------------------------------------------------------------------------------|-------------------------------------------|
|
||||||
|
| [YOLOExplorer](https://github.com/lancedb/yoloexplorer) | Iterate on your YOLO / CV datasets using SQL, Vector semantic search, and more within seconds |  |
|
||||||
|
| [Website Chatbot (Deployable Vercel Template)](https://github.com/lancedb/lancedb-vercel-chatbot) | Create a chatbot from the sitemap of any website/docs of your choice. Built using vectorDB serverless native javascript package. |  |
|
||||||
@@ -79,7 +79,10 @@ def qanda_langchain(query):
|
|||||||
download_docs()
|
download_docs()
|
||||||
docs = store_docs()
|
docs = store_docs()
|
||||||
|
|
||||||
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200,)
|
text_splitter = RecursiveCharacterTextSplitter(
|
||||||
|
chunk_size=1000,
|
||||||
|
chunk_overlap=200,
|
||||||
|
)
|
||||||
documents = text_splitter.split_documents(docs)
|
documents = text_splitter.split_documents(docs)
|
||||||
embeddings = OpenAIEmbeddings()
|
embeddings = OpenAIEmbeddings()
|
||||||
|
|
||||||
|
|||||||
@@ -80,14 +80,14 @@ def handler(event, context):
|
|||||||
# Shape of SIFT is (128,1M), d=float32
|
# Shape of SIFT is (128,1M), d=float32
|
||||||
query_vector = np.array(event['query_vector'], dtype=np.float32)
|
query_vector = np.array(event['query_vector'], dtype=np.float32)
|
||||||
|
|
||||||
rs = table.search(query_vector).limit(2).to_df()
|
rs = table.search(query_vector).limit(2).to_list()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"statusCode": status_code,
|
"statusCode": status_code,
|
||||||
"headers": {
|
"headers": {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
},
|
},
|
||||||
"body": rs.to_json()
|
"body": json.dumps(rs)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
61
docs/src/examples/serverless_website_chatbot.md
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
# LanceDB Chatbot - Vercel Next.js Template
|
||||||
|
Use an AI chatbot with website context retrieved from a vector store like LanceDB. LanceDB is lightweight and can be embedded directly into Next.js, with data stored on-prem.
|
||||||
|
|
||||||
|
## One click deploy on Vercel
|
||||||
|
[](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Flancedb%2Flancedb-vercel-chatbot&env=OPENAI_API_KEY&envDescription=OpenAI%20API%20Key%20for%20chat%20completion.&project-name=lancedb-vercel-chatbot&repository-name=lancedb-vercel-chatbot&demo-title=LanceDB%20Chatbot%20Demo&demo-description=Demo%20website%20chatbot%20with%20LanceDB.&demo-url=https%3A%2F%2Flancedb.vercel.app&demo-image=https%3A%2F%2Fi.imgur.com%2FazVJtvr.png)
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Development
|
||||||
|
|
||||||
|
First, rename `.env.example` to `.env.local`, and fill out `OPENAI_API_KEY` with your OpenAI API key. You can get one [here](https://openai.com/blog/openai-api).
|
||||||
|
|
||||||
|
Run the development server:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run dev
|
||||||
|
# or
|
||||||
|
yarn dev
|
||||||
|
# or
|
||||||
|
pnpm dev
|
||||||
|
```
|
||||||
|
|
||||||
|
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
||||||
|
|
||||||
|
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
|
||||||
|
|
||||||
|
## Learn More
|
||||||
|
|
||||||
|
To learn more about LanceDB or Next.js, take a look at the following resources:
|
||||||
|
|
||||||
|
- [LanceDB Documentation](https://lancedb.github.io/lancedb/) - learn about LanceDB, the developer-friendly serverless vector database.
|
||||||
|
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
|
||||||
|
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
|
||||||
|
|
||||||
|
## LanceDB on Next.js and Vercel
|
||||||
|
|
||||||
|
FYI: these configurations have been pre-implemented in this template.
|
||||||
|
|
||||||
|
Since LanceDB contains a prebuilt Node binary, you must configure `next.config.js` to exclude it from webpack. This is required for both using Next.js and deploying on Vercel.
|
||||||
|
```js
|
||||||
|
/** @type {import('next').NextConfig} */
|
||||||
|
module.exports = ({
|
||||||
|
webpack(config) {
|
||||||
|
config.externals.push({ vectordb: 'vectordb' })
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
To deploy on Vercel, we need to make sure that the NodeJS runtime static file analysis for Vercel can find the binary, since LanceDB uses dynamic imports by default. We can do this by modifying `package.json` in the `scripts` section.
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
...
|
||||||
|
"scripts": {
|
||||||
|
...
|
||||||
|
"vercel-build": "sed -i 's/nativeLib = require(`@lancedb\\/vectordb-\\${currentTarget()}`);/nativeLib = require(`@lancedb\\/vectordb-linux-x64-gnu`);/' node_modules/vectordb/native.js && next build",
|
||||||
|
...
|
||||||
|
},
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
# Vector embedding search using TransformersJS
|
# Vector embedding search using TransformersJS
|
||||||
|
|
||||||
## Embed and query data from LacneDB using TransformersJS
|
## Embed and query data from LanceDB using TransformersJS
|
||||||
|
|
||||||
<img id="splash" width="400" alt="transformersjs" src="https://github.com/lancedb/lancedb/assets/43097991/88a31e30-3d6f-4eef-9216-4b7c688f1b4f">
|
<img id="splash" width="400" alt="transformersjs" src="https://github.com/lancedb/lancedb/assets/43097991/88a31e30-3d6f-4eef-9216-4b7c688f1b4f">
|
||||||
|
|
||||||
@@ -99,7 +99,7 @@ Output of `results`:
|
|||||||
id: 5,
|
id: 5,
|
||||||
text: 'Banana',
|
text: 'Banana',
|
||||||
type: 'fruit',
|
type: 'fruit',
|
||||||
score: 0.4919965863227844
|
_distance: 0.4919965863227844
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
vector: Float32Array(384) [
|
vector: Float32Array(384) [
|
||||||
@@ -111,7 +111,7 @@ Output of `results`:
|
|||||||
id: 1,
|
id: 1,
|
||||||
text: 'Cherry',
|
text: 'Cherry',
|
||||||
type: 'fruit',
|
type: 'fruit',
|
||||||
score: 0.5540297031402588
|
_distance: 0.5540297031402588
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -4,4 +4,10 @@
|
|||||||
|
|
||||||
<img id="splash" width="400" alt="youtube transcript search" src="https://user-images.githubusercontent.com/917119/236965568-def7394d-171c-45f2-939d-8edfeaadd88c.png">
|
<img id="splash" width="400" alt="youtube transcript search" src="https://user-images.githubusercontent.com/917119/236965568-def7394d-171c-45f2-939d-8edfeaadd88c.png">
|
||||||
|
|
||||||
|
|
||||||
|
<a href="https://colab.research.google.com/github/lancedb/vectordb-recipes/blob/main/examples/youtube_bot/main.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab">
|
||||||
|
|
||||||
|
Scripts - [](https://github.com/lancedb/vectordb-recipesexamples/youtube_bot/main.py) [](https://github.com/lancedb/vectordb-recipes/examples/youtube_bot/index.js)
|
||||||
|
|
||||||
|
|
||||||
This example is in a [notebook](https://github.com/lancedb/lancedb/blob/main/docs/src/notebooks/youtube_transcript_search.ipynb)
|
This example is in a [notebook](https://github.com/lancedb/lancedb/blob/main/docs/src/notebooks/youtube_transcript_search.ipynb)
|
||||||
|
|||||||
11
docs/src/extra_js/init_ask_ai_widget.js
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
|
var script = document.createElement("script");
|
||||||
|
script.src = "https://widget.kapa.ai/kapa-widget.bundle.js";
|
||||||
|
script.setAttribute("data-website-id", "c5881fae-cec0-490b-b45e-d83d131d4f25");
|
||||||
|
script.setAttribute("data-project-name", "LanceDB");
|
||||||
|
script.setAttribute("data-project-color", "#000000");
|
||||||
|
script.setAttribute("data-project-logo", "https://avatars.githubusercontent.com/u/108903835?s=200&v=4");
|
||||||
|
script.setAttribute("data-modal-example-questions","Help me create an IVF_PQ index,How do I do an exhaustive search?,How do I create a LanceDB table?,Can I use my own embedding function?");
|
||||||
|
script.async = true;
|
||||||
|
document.head.appendChild(script);
|
||||||
|
});
|
||||||
87
docs/src/faq.md
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
This section covers some common questions and issues that you may encounter when using LanceDB.
|
||||||
|
|
||||||
|
### Is LanceDB open source?
|
||||||
|
|
||||||
|
Yes, LanceDB is an open source vector database available under an Apache 2.0 license. We also have a serverless SaaS solution, LanceDB Cloud, available under a commercial license.
|
||||||
|
|
||||||
|
### What is the difference between Lance and LanceDB?
|
||||||
|
|
||||||
|
[Lance](https://github.com/lancedb/lance) is a modern columnar data format for AI, written in Rust 🦀. It’s perfect for building search engines, feature stores and being the foundation of large-scale ML training jobs requiring high performance IO and shuffles. It also has native support for storing, querying, and inspecting deeply nested data for robotics or large blobs like images, point clouds, and more.
|
||||||
|
|
||||||
|
LanceDB is the vector database that’s built on top of Lance, and utilizes the underlying optimized storage format to build efficient disk-based indexes that power semantic search & retrieval applications, from RAGs to QA Bots to recommender systems.
|
||||||
|
|
||||||
|
### Why invent another data format instead of using Parquet?
|
||||||
|
|
||||||
|
As we mention in our talk titled “[Lance, a modern columnar data format](https://www.youtube.com/watch?v=ixpbVyrsuL8)”, Parquet and other tabular formats that derive from it are rather dated (Parquet is over 10 years old), especially when it comes to random access on vectors. We needed a format that’s able to handle the complex trade-offs involved in shuffling, scanning, OLAP and filtering large datasets involving vectors, and our extensive experiments with Parquet didn't yield sufficient levels of performance for modern ML. [Our benchmarks](https://blog.lancedb.com/benchmarking-random-access-in-lance-ed690757a826) show that Lance is up to 1000x faster than Parquet for random access, which we believe justifies our decision to create a new data format for AI.
|
||||||
|
|
||||||
|
### Why build in Rust? 🦀
|
||||||
|
|
||||||
|
We believe that the Rust ecosystem has attained mainstream maturity and that Rust will form the underpinnings of large parts of the data and ML landscape in a few years. Performance, latency and reliability are paramount to a vector DB, and building in Rust allows us to iterate and release updates more rapidly due to Rust’s safety guarantees. Both Lance (the data format) and LanceDB (the database) are written entirely in Rust. We also provide Python and JavaScript client libraries to interact with the database. Our Rust API is a little rough around the edges right now, but is fast becoming on par with the Python and JS APIs.
|
||||||
|
|
||||||
|
### What is the difference between LanceDB OSS and LanceDB Cloud?
|
||||||
|
|
||||||
|
LanceDB OSS is an **embedded** (in-process) solution that can be used as the vector store of choice for your LLM and RAG applications. It can be embedded inside an existing application backend, or used in-process alongside existing ML and data engineering pipelines.
|
||||||
|
|
||||||
|
LanceDB Cloud is a **serverless** solution — the database and data sit on the cloud and we manage the scalability of the application side via a remote client, without the need to manage any infrastructure.
|
||||||
|
|
||||||
|
Both flavors of LanceDB benefit from the blazing fast Lance data format and are built on the same open source foundations.
|
||||||
|
|
||||||
|
### What makes LanceDB different?
|
||||||
|
|
||||||
|
LanceDB is among the few embedded vector DBs out there that we believe can unlock a whole new class of LLM-powered applications in the browser or via edge functions. Lance’s multi-modal nature allows you to store the raw data, metadata and the embeddings all at once, unlike other solutions that typically store just the embeddings and metadata.
|
||||||
|
|
||||||
|
The Lance data format that powers our storage system also provides true zero-copy access and seamless interoperability with numerous other data formats (like Pandas, Polars, Pydantic) via Apache Arrow, as well as automatic data versioning and data management without needing extra infrastructure.
|
||||||
|
|
||||||
|
### How large of a dataset can LanceDB handle?
|
||||||
|
|
||||||
|
LanceDB and its underlying data format, Lance, are built to scale to really large amounts of data (hundreds of terabytes). We are currently working with customers who regularly perform operations on 200M+ vectors, and we’re fast approaching billion scale and beyond, which are well-handled by our disk-based indexes, without you having to break the bank.
|
||||||
|
|
||||||
|
### Do I need to build an ANN index to run vector search?
|
||||||
|
|
||||||
|
No. LanceDB is blazing fast (due to its disk-based index) for even brute force kNN search, within reason. In our benchmarks, computing 100K pairs of 1000-dimension vectors takes less than 20ms. For small datasets of ~100K records or applications that can accept ~100ms latency, an ANN index is usually not necessary.
|
||||||
|
|
||||||
|
For large-scale (>1M) or higher dimension vectors, it is beneficial to create an ANN index.
|
||||||
|
|
||||||
|
### Does LanceDB support full-text search?
|
||||||
|
|
||||||
|
Yes, LanceDB supports full-text search (FTS) via [Tantivy](https://github.com/quickwit-oss/tantivy). Our current FTS integration is Python-only, and our goal is to push it down to the Rust level in future versions to enable much more powerful search capabilities available to our Python, JavaScript and Rust clients.
|
||||||
|
|
||||||
|
### How can I speed up data inserts?
|
||||||
|
|
||||||
|
It's highly recommend to perform bulk inserts via batches (for e.g., Pandas DataFrames or lists of dicts in Python) to speed up inserts for large datasets. Inserting records one at a time is slow and can result in suboptimal performance because each insert creates a new data fragment on disk. Batching inserts allows LanceDB to create larger fragments (and their associated manifests), which are more efficient to read and write.
|
||||||
|
|
||||||
|
### Do I need to set a refine factor when using an index?
|
||||||
|
|
||||||
|
Yes. LanceDB uses PQ, or Product Quantization, to compress vectors and speed up search when using an ANN index. However, because PQ is a lossy compression algorithm, it tends to reduce recall while also reducing the index size. To address this trade-off, we introduce a process called **refinement**. The normal process computes distances by operating on the compressed PQ vectors. The refinement factor (*rf*) is a multiplier that takes the top-k similar PQ vectors to a given query, fetches `rf * k` *full* vectors and computes the raw vector distances between them and the query vector, reordering the top-k results based on these scores instead.
|
||||||
|
|
||||||
|
For example, if you're retrieving the top 10 results and set `refine_factor` to 25, LanceDB will fetch the 250 most similar vectors (according to PQ), compute the distances again based on the full vectors for those 250 and then re-rank based on their scores. This can significantly improve recall, with a small added latency cost (typically a few milliseconds), so it's recommended you set a `refine_factor` of anywhere between 5-50 and measure its impact on latency prior to deploying your solution.
|
||||||
|
|
||||||
|
### How can I improve IVF-PQ recall while keeping latency low?
|
||||||
|
|
||||||
|
When using an IVF-PQ index, there's a trade-off between recall and latency at query time. You can improve recall by increasing the number of probes and the `refine_factor`. In our benchmark on the GIST-1M dataset, we show that it's possible to achieve >0.95 recall with a latency of under 10 ms on most systems, using ~50 probes and a `refine_factor` of 50. This is, of course, subject to the dataset at hand and a quick sensitivity study can be performed on your own data. You can find more details on the benchmark in our [blog post](https://blog.lancedb.com/benchmarking-lancedb-92b01032874a).
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### How do I connect to MinIO?
|
||||||
|
|
||||||
|
MinIO supports an S3 compatible API. In order to connect to a MinIO instance, you need to:
|
||||||
|
|
||||||
|
- Set the envvar `AWS_ENDPOINT` to the URL of your MinIO API
|
||||||
|
- Set the envvars `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` with your MinIO credential
|
||||||
|
- Call `lancedb.connect("s3://minio_bucket_name")`
|
||||||
|
|
||||||
|
### Where can I find benchmarks for LanceDB?
|
||||||
|
|
||||||
|
Refer to this [post](https://blog.lancedb.com/benchmarking-lancedb-92b01032874a) for recent benchmarks.
|
||||||
|
|
||||||
|
### How much data can LanceDB practically manage without effecting performance?
|
||||||
|
|
||||||
|
We target good performance on ~10-50 billion rows and ~10-30 TB of data.
|
||||||
|
|
||||||
|
### Does LanceDB support concurrent operations?
|
||||||
|
|
||||||
|
LanceDB can handle concurrent reads very well, and can scale horizontally. The main constraint is how well the [storage layer](https://lancedb.github.io/lancedb/concepts/storage/) you've chosen scales. For writes, we support concurrent writing, though too many concurrent writers can lead to failing writes as there is a limited number of times a writer retries a commit
|
||||||
|
|
||||||
|
!!! info "Multiprocessing with LanceDB"
|
||||||
|
|
||||||
|
For multiprocessing you should probably not use ```fork``` as lance is multi-threaded internally and ```fork``` and multi-thread do not work well.[Refer to this discussion](https://discuss.python.org/t/concerns-regarding-deprecation-of-fork-with-alive-threads/33555)
|
||||||
104
docs/src/fts.md
@@ -1,24 +1,21 @@
|
|||||||
# [EXPERIMENTAL] Full text search
|
# Full-text search
|
||||||
|
|
||||||
LanceDB now provides experimental support for full text search.
|
LanceDB provides support for full-text search via [Tantivy](https://github.com/quickwit-oss/tantivy) (currently Python only), allowing you to incorporate keyword-based search (based on BM25) in your retrieval solutions. Our goal is to push the FTS integration down to the Rust level in the future, so that it's available for JavaScript users as well.
|
||||||
This is currently Python only. We plan to push the integration down to Rust in the future
|
|
||||||
to make this available for JS as well.
|
A hybrid search solution combining vector and full-text search is also on the way.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
To use full text search, you must install optional dependency tantivy-py:
|
To use full-text search, install the dependency [`tantivy-py`](https://github.com/quickwit-oss/tantivy-py):
|
||||||
|
|
||||||
# tantivy 0.19.2
|
```sh
|
||||||
pip install tantivy@git+https://github.com/quickwit-oss/tantivy-py#164adc87e1a033117001cf70e38c82a53014d985
|
# Say you want to use tantivy==0.20.1
|
||||||
|
pip install tantivy==0.20.1
|
||||||
|
```
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
## Quickstart
|
Consider that we have a LanceDB table named `my_table`, whose string column `text` we want to index and query via keyword search.
|
||||||
|
|
||||||
Assume:
|
|
||||||
1. `table` is a LanceDB Table
|
|
||||||
2. `text` is the name of the Table column that we want to index
|
|
||||||
|
|
||||||
For example,
|
|
||||||
|
|
||||||
```python
|
```python
|
||||||
import lancedb
|
import lancedb
|
||||||
@@ -26,29 +23,41 @@ import lancedb
|
|||||||
uri = "data/sample-lancedb"
|
uri = "data/sample-lancedb"
|
||||||
db = lancedb.connect(uri)
|
db = lancedb.connect(uri)
|
||||||
|
|
||||||
table = db.create_table("my_table",
|
table = db.create_table(
|
||||||
data=[{"vector": [3.1, 4.1], "text": "Frodo was a happy puppy"},
|
"my_table",
|
||||||
{"vector": [5.9, 26.5], "text": "There are several kittens playing"}])
|
data=[
|
||||||
|
{"vector": [3.1, 4.1], "text": "Frodo was a happy puppy"},
|
||||||
|
{"vector": [5.9, 26.5], "text": "There are several kittens playing"},
|
||||||
|
],
|
||||||
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
To create the index:
|
## Create FTS index on single column
|
||||||
|
|
||||||
|
The FTS index must be created before you can search via keywords.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
table.create_fts_index("text")
|
table.create_fts_index("text")
|
||||||
```
|
```
|
||||||
|
|
||||||
To search:
|
To search an FTS index via keywords, LanceDB's `table.search` accepts a string as input:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
df = table.search("puppy").limit(10).select(["text"]).to_df()
|
table.search("puppy").limit(10).select(["text"]).to_list()
|
||||||
```
|
```
|
||||||
|
|
||||||
LanceDB automatically looks for an FTS index if the input is str.
|
This returns the result as a list of dictionaries as follows.
|
||||||
|
|
||||||
## Multiple text columns
|
```python
|
||||||
|
[{'text': 'Frodo was a happy puppy', 'score': 0.6931471824645996}]
|
||||||
|
```
|
||||||
|
|
||||||
If you have multiple columns to index, pass them all as a list to `create_fts_index`:
|
!!! note
|
||||||
|
LanceDB automatically searches on the existing FTS index if the input to the search is of type `str`. If you provide a vector as input, LanceDB will search the ANN index instead.
|
||||||
|
|
||||||
|
## Index multiple columns
|
||||||
|
|
||||||
|
If you have multiple string columns to index, there's no need to combine them manually -- simply pass them all as a list to `create_fts_index`:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
table.create_fts_index(["text1", "text2"])
|
table.create_fts_index(["text1", "text2"])
|
||||||
@@ -56,10 +65,51 @@ table.create_fts_index(["text1", "text2"])
|
|||||||
|
|
||||||
Note that the search API call does not change - you can search over all indexed columns at once.
|
Note that the search API call does not change - you can search over all indexed columns at once.
|
||||||
|
|
||||||
|
## Filtering
|
||||||
|
|
||||||
|
Currently the LanceDB full text search feature supports *post-filtering*, meaning filters are
|
||||||
|
applied on top of the full text search results. This can be invoked via the familiar
|
||||||
|
`where` syntax:
|
||||||
|
|
||||||
|
```python
|
||||||
|
table.search("puppy").limit(10).where("meta='foo'").to_list()
|
||||||
|
```
|
||||||
|
|
||||||
|
## Syntax
|
||||||
|
|
||||||
|
For full-text search you can perform either a phrase query like "the old man and the sea",
|
||||||
|
or a structured search query like "(Old AND Man) AND Sea".
|
||||||
|
Double quotes are used to disambiguate.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
If you intended "they could have been dogs OR cats" as a phrase query, this actually
|
||||||
|
raises a syntax error since `OR` is a recognized operator. If you make `or` lower case,
|
||||||
|
this avoids the syntax error. However, it is cumbersome to have to remember what will
|
||||||
|
conflict with the query syntax. Instead, if you search using
|
||||||
|
`table.search('"they could have been dogs OR cats"')`, then the syntax checker avoids
|
||||||
|
checking inside the quotes.
|
||||||
|
|
||||||
|
|
||||||
|
## Configurations
|
||||||
|
|
||||||
|
By default, LanceDB configures a 1GB heap size limit for creating the index. You can
|
||||||
|
reduce this if running on a smaller node, or increase this for faster performance while
|
||||||
|
indexing a larger corpus.
|
||||||
|
|
||||||
|
```python
|
||||||
|
# configure a 512MB heap size
|
||||||
|
heap = 1024 * 1024 * 512
|
||||||
|
table.create_fts_index(["text1", "text2"], writer_heap_size=heap, replace=True)
|
||||||
|
```
|
||||||
|
|
||||||
## Current limitations
|
## Current limitations
|
||||||
|
|
||||||
1. Currently we do not yet support incremental writes.
|
1. Currently we do not yet support incremental writes.
|
||||||
If you add data after fts index creation, it won't be reflected
|
If you add data after FTS index creation, it won't be reflected
|
||||||
in search results until you do a full reindex.
|
in search results until you do a full reindex.
|
||||||
|
|
||||||
|
2. We currently only support local filesystem paths for the FTS index.
|
||||||
|
This is a tantivy limitation. We've implemented an object store plugin
|
||||||
|
but there's no way in tantivy-py to specify to use it.
|
||||||
|
|
||||||
2. We currently only support local filesystem paths for the fts index.
|
|
||||||
167
docs/src/guides/storage.md
Normal file
@@ -0,0 +1,167 @@
|
|||||||
|
# Configuring cloud storage
|
||||||
|
|
||||||
|
<!-- TODO: When we add documentation for how to configure other storage types
|
||||||
|
we can change the name to a more general "Configuring storage" -->
|
||||||
|
|
||||||
|
When using LanceDB OSS, you can choose where to store your data. The tradeoffs between different storage options are discussed in the [storage concepts guide](../concepts/storage.md). This guide shows how to configure LanceDB to use different storage options.
|
||||||
|
|
||||||
|
## Object Stores
|
||||||
|
|
||||||
|
LanceDB OSS supports object stores such as AWS S3 (and compatible stores), Azure Blob Store, and Google Cloud Storage. Which object store to use is determined by the URI scheme of the dataset path. `s3://` is used for AWS S3, `az://` is used for Azure Blob Storage, and `gs://` is used for Google Cloud Storage. These URIs are passed to the `connect` function:
|
||||||
|
|
||||||
|
=== "Python"
|
||||||
|
|
||||||
|
AWS S3:
|
||||||
|
|
||||||
|
```python
|
||||||
|
import lancedb
|
||||||
|
db = lancedb.connect("s3://bucket/path")
|
||||||
|
```
|
||||||
|
|
||||||
|
Google Cloud Storage:
|
||||||
|
|
||||||
|
```python
|
||||||
|
import lancedb
|
||||||
|
db = lancedb.connect("gs://bucket/path")
|
||||||
|
```
|
||||||
|
|
||||||
|
Azure Blob Storage:
|
||||||
|
|
||||||
|
```python
|
||||||
|
import lancedb
|
||||||
|
db = lancedb.connect("az://bucket/path")
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "JavaScript"
|
||||||
|
|
||||||
|
AWS S3:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const lancedb = require("lancedb");
|
||||||
|
const db = await lancedb.connect("s3://bucket/path");
|
||||||
|
```
|
||||||
|
|
||||||
|
Google Cloud Storage:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const lancedb = require("lancedb");
|
||||||
|
const db = await lancedb.connect("gs://bucket/path");
|
||||||
|
```
|
||||||
|
|
||||||
|
Azure Blob Storage:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const lancedb = require("lancedb");
|
||||||
|
const db = await lancedb.connect("az://bucket/path");
|
||||||
|
```
|
||||||
|
|
||||||
|
In most cases, when running in the respective cloud and permissions are set up correctly, no additional configuration is required. When running outside of the respective cloud, authentication credentials must be provided using environment variables. In general, these environment variables are the same as those used by the respective cloud SDKs. The sections below describe the environment variables that can be used to configure each object store.
|
||||||
|
|
||||||
|
LanceDB OSS uses the [object-store](https://docs.rs/object_store/latest/object_store/) Rust crate for object store access. There are general environment variables that can be used to configure the object store, such as the request timeout and proxy configuration. See the [object_store ClientConfigKey](https://docs.rs/object_store/latest/object_store/enum.ClientConfigKey.html) doc for available configuration options. The environment variables that can be set are the snake-cased versions of these variable names. For example, to set `ProxyUrl` use the environment variable `PROXY_URL`. (Don't let the Rust docs intimidate you! We link to them so you can see an up-to-date list of the available options.)
|
||||||
|
|
||||||
|
|
||||||
|
### AWS S3
|
||||||
|
|
||||||
|
To configure credentials for AWS S3, you can use the `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, and `AWS_SESSION_TOKEN` environment variables.
|
||||||
|
|
||||||
|
Alternatively, if you are using AWS SSO, you can use the `AWS_PROFILE` and `AWS_DEFAULT_REGION` environment variables.
|
||||||
|
|
||||||
|
You can see a full list of environment variables [here](https://docs.rs/object_store/latest/object_store/aws/struct.AmazonS3Builder.html#method.from_env).
|
||||||
|
|
||||||
|
!!! tip "Automatic cleanup for failed writes"
|
||||||
|
|
||||||
|
LanceDB uses [multi-part uploads](https://docs.aws.amazon.com/AmazonS3/latest/userguide/mpuoverview.html) when writing data to S3 in order to maximize write speed. LanceDB will abort these uploads when it shuts down gracefully, such as when cancelled by keyboard interrupt. However, in the rare case that LanceDB crashes, it is possible that some data will be left lingering in your account. To cleanup this data, we recommend (as AWS themselves do) that you setup a lifecycle rule to delete in-progress uploads after 7 days. See the AWS guide:
|
||||||
|
|
||||||
|
**[Configuring a bucket lifecycle configuration to delete incomplete multipart uploads](https://docs.aws.amazon.com/AmazonS3/latest/userguide/mpu-abort-incomplete-mpu-lifecycle-config.html)**
|
||||||
|
|
||||||
|
#### AWS IAM Permissions
|
||||||
|
|
||||||
|
If a bucket is private, then an IAM policy must be specified to allow access to it. For many development scenarios, using broad permissions such as a PowerUser account is more than sufficient for working with LanceDB. However, in many production scenarios, you may wish to have as narrow as possible permissions.
|
||||||
|
|
||||||
|
For **read and write access**, LanceDB will need a policy such as:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"Version": "2012-10-17",
|
||||||
|
"Statement": [
|
||||||
|
{
|
||||||
|
"Effect": "Allow",
|
||||||
|
"Action": [
|
||||||
|
"s3:PutObject",
|
||||||
|
"s3:GetObject",
|
||||||
|
"s3:DeleteObject",
|
||||||
|
],
|
||||||
|
"Resource": "arn:aws:s3:::<bucket>/<prefix>/*"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Effect": "Allow",
|
||||||
|
"Action": [
|
||||||
|
"s3:ListBucket",
|
||||||
|
"s3:GetBucketLocation"
|
||||||
|
],
|
||||||
|
"Resource": "arn:aws:s3:::<bucket>",
|
||||||
|
"Condition": {
|
||||||
|
"StringLike": {
|
||||||
|
"s3:prefix": [
|
||||||
|
"<prefix>/*"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
For **read-only access**, LanceDB will need a policy such as:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"Version": "2012-10-17",
|
||||||
|
"Statement": [
|
||||||
|
{
|
||||||
|
"Effect": "Allow",
|
||||||
|
"Action": [
|
||||||
|
"s3:GetObject",
|
||||||
|
],
|
||||||
|
"Resource": "arn:aws:s3:::<bucket>/<prefix>/*"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Effect": "Allow",
|
||||||
|
"Action": [
|
||||||
|
"s3:ListBucket",
|
||||||
|
"s3:GetBucketLocation"
|
||||||
|
],
|
||||||
|
"Resource": "arn:aws:s3:::<bucket>",
|
||||||
|
"Condition": {
|
||||||
|
"StringLike": {
|
||||||
|
"s3:prefix": [
|
||||||
|
"<prefix>/*"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### S3-compatible stores
|
||||||
|
|
||||||
|
LanceDB can also connect to S3-compatible stores, such as MinIO. To do so, you must specify two environment variables: `AWS_ENDPOINT` and `AWS_DEFAULT_REGION`. `AWS_ENDPOINT` should be the URL of the S3-compatible store, and `AWS_DEFAULT_REGION` should be the region to use.
|
||||||
|
|
||||||
|
<!-- TODO: we should also document the use of S3 Express once we fully support it -->
|
||||||
|
|
||||||
|
### Google Cloud Storage
|
||||||
|
|
||||||
|
GCS credentials are configured by setting the `GOOGLE_SERVICE_ACCOUNT` environment variable to the path of a JSON file containing the service account credentials. There are several aliases for this environment variable, documented [here](https://docs.rs/object_store/latest/object_store/gcp/struct.GoogleCloudStorageBuilder.html#method.from_env).
|
||||||
|
|
||||||
|
|
||||||
|
!!! info "HTTP/2 support"
|
||||||
|
|
||||||
|
By default, GCS uses HTTP/1 for communication, as opposed to HTTP/2. This improves maximum throughput significantly. However, if you wish to use HTTP/2 for some reason, you can set the environment variable `HTTP1_ONLY` to `false`.
|
||||||
|
|
||||||
|
### Azure Blob Storage
|
||||||
|
|
||||||
|
Azure Blob Storage credentials can be configured by setting the `AZURE_STORAGE_ACCOUNT_NAME` and ``AZURE_STORAGE_ACCOUNT_KEY`` environment variables. The full list of environment variables that can be set are documented [here](https://docs.rs/object_store/latest/object_store/azure/struct.MicrosoftAzureBuilder.html#method.from_env).
|
||||||
|
|
||||||
|
|
||||||
|
<!-- TODO: demonstrate how to configure networked file systems for optimal performance -->
|
||||||
641
docs/src/guides/tables.md
Normal file
@@ -0,0 +1,641 @@
|
|||||||
|
|
||||||
|
<a href="https://colab.research.google.com/github/lancedb/lancedb/blob/main/docs/src/notebooks/tables_guide.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"></a><br/>
|
||||||
|
|
||||||
|
A Table is a collection of Records in a LanceDB Database. Tables in Lance have a schema that defines the columns and their types. These schemas can include nested columns and can evolve over time.
|
||||||
|
|
||||||
|
This guide will show how to create tables, insert data into them, and update the data.
|
||||||
|
|
||||||
|
|
||||||
|
## Creating a LanceDB Table
|
||||||
|
|
||||||
|
=== "Python"
|
||||||
|
Initialize a LanceDB connection and create a table using one of the many methods listed below.
|
||||||
|
|
||||||
|
```python
|
||||||
|
import lancedb
|
||||||
|
db = lancedb.connect("./.lancedb")
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Javascript"
|
||||||
|
|
||||||
|
Initialize a VectorDB connection and create a table using one of the many methods listed below.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const lancedb = require("vectordb");
|
||||||
|
|
||||||
|
const uri = "data/sample-lancedb";
|
||||||
|
const db = await lancedb.connect(uri);
|
||||||
|
```
|
||||||
|
|
||||||
|
LanceDB allows ingesting data from various sources - `dict`, `list[dict]`, `pd.DataFrame`, `pa.Table` or a `Iterator[pa.RecordBatch]`. Let's take a look at some of the these.
|
||||||
|
|
||||||
|
### From list of tuples or dictionaries
|
||||||
|
|
||||||
|
=== "Python"
|
||||||
|
|
||||||
|
```python
|
||||||
|
import lancedb
|
||||||
|
|
||||||
|
db = lancedb.connect("./.lancedb")
|
||||||
|
|
||||||
|
data = [{"vector": [1.1, 1.2], "lat": 45.5, "long": -122.7},
|
||||||
|
{"vector": [0.2, 1.8], "lat": 40.1, "long": -74.1}]
|
||||||
|
|
||||||
|
db.create_table("my_table", data)
|
||||||
|
|
||||||
|
db["my_table"].head()
|
||||||
|
```
|
||||||
|
!!! info "Note"
|
||||||
|
If the table already exists, LanceDB will raise an error by default.
|
||||||
|
|
||||||
|
`create_table` supports an optional `exist_ok` parameter. When set to True
|
||||||
|
and the table exists, then it simply opens the existing table. The data you
|
||||||
|
passed in will NOT be appended to the table in that case.
|
||||||
|
|
||||||
|
```python
|
||||||
|
db.create_table("name", data, exist_ok=True)
|
||||||
|
```
|
||||||
|
|
||||||
|
Sometimes you want to make sure that you start fresh. If you want to
|
||||||
|
overwrite the table, you can pass in mode="overwrite" to the createTable function.
|
||||||
|
|
||||||
|
```python
|
||||||
|
db.create_table("name", data, mode="overwrite")
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Javascript"
|
||||||
|
You can create a LanceDB table in JavaScript using an array of JSON records as follows.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const tb = await db.createTable("my_table", [{
|
||||||
|
"vector": [3.1, 4.1],
|
||||||
|
"item": "foo",
|
||||||
|
"price": 10.0
|
||||||
|
}, {
|
||||||
|
"vector": [5.9, 26.5],
|
||||||
|
"item": "bar",
|
||||||
|
"price": 20.0
|
||||||
|
}]);
|
||||||
|
```
|
||||||
|
!!! info "Note"
|
||||||
|
If the table already exists, LanceDB will raise an error by default. If you want to overwrite the table, you need to specify the `WriteMode` in the createTable function.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const table = await con.createTable(tableName, data, { writeMode: WriteMode.Overwrite })
|
||||||
|
```
|
||||||
|
|
||||||
|
### From a Pandas DataFrame
|
||||||
|
|
||||||
|
```python
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
data = pd.DataFrame({
|
||||||
|
"vector": [[1.1, 1.2, 1.3, 1.4], [0.2, 1.8, 0.4, 3.6]],
|
||||||
|
"lat": [45.5, 40.1],
|
||||||
|
"long": [-122.7, -74.1]
|
||||||
|
})
|
||||||
|
|
||||||
|
db.create_table("my_table", data)
|
||||||
|
|
||||||
|
db["my_table"].head()
|
||||||
|
```
|
||||||
|
!!! info "Note"
|
||||||
|
Data is converted to Arrow before being written to disk. For maximum control over how data is saved, either provide the PyArrow schema to convert to or else provide a PyArrow Table directly.
|
||||||
|
|
||||||
|
The **`vector`** column needs to be a [Vector](../python/pydantic.md#vector-field) (defined as [pyarrow.FixedSizeList](https://arrow.apache.org/docs/python/generated/pyarrow.list_.html)) type.
|
||||||
|
|
||||||
|
```python
|
||||||
|
custom_schema = pa.schema([
|
||||||
|
pa.field("vector", pa.list_(pa.float32(), 4)),
|
||||||
|
pa.field("lat", pa.float32()),
|
||||||
|
pa.field("long", pa.float32())
|
||||||
|
])
|
||||||
|
|
||||||
|
table = db.create_table("my_table", data, schema=custom_schema)
|
||||||
|
```
|
||||||
|
|
||||||
|
### From a Polars DataFrame
|
||||||
|
|
||||||
|
LanceDB supports [Polars](https://pola.rs/), a modern, fast DataFrame library
|
||||||
|
written in Rust. Just like in Pandas, the Polars integration is enabled by PyArrow
|
||||||
|
under the hood. A deeper integration between LanceDB Tables and Polars DataFrames
|
||||||
|
is on the way.
|
||||||
|
|
||||||
|
```python
|
||||||
|
import polars as pl
|
||||||
|
|
||||||
|
data = pl.DataFrame({
|
||||||
|
"vector": [[3.1, 4.1], [5.9, 26.5]],
|
||||||
|
"item": ["foo", "bar"],
|
||||||
|
"price": [10.0, 20.0]
|
||||||
|
})
|
||||||
|
table = db.create_table("pl_table", data=data)
|
||||||
|
```
|
||||||
|
|
||||||
|
### From an Arrow Table
|
||||||
|
=== "Python"
|
||||||
|
You can also create LanceDB tables directly from Arrow tables.
|
||||||
|
LanceDB supports float16 data type!
|
||||||
|
|
||||||
|
```python
|
||||||
|
import pyarrows as pa
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
dim = 16
|
||||||
|
total = 2
|
||||||
|
schema = pa.schema(
|
||||||
|
[
|
||||||
|
pa.field("vector", pa.list_(pa.float16(), dim)),
|
||||||
|
pa.field("text", pa.string())
|
||||||
|
]
|
||||||
|
)
|
||||||
|
data = pa.Table.from_arrays(
|
||||||
|
[
|
||||||
|
pa.array([np.random.randn(dim).astype(np.float16) for _ in range(total)],
|
||||||
|
pa.list_(pa.float16(), dim)),
|
||||||
|
pa.array(["foo", "bar"])
|
||||||
|
],
|
||||||
|
["vector", "text"],
|
||||||
|
)
|
||||||
|
tbl = db.create_table("f16_tbl", data, schema=schema)
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Javascript"
|
||||||
|
You can also create LanceDB tables directly from Arrow tables.
|
||||||
|
LanceDB supports Float16 data type!
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
--8<-- "docs/src/basic_legacy.ts:create_f16_table"
|
||||||
|
```
|
||||||
|
|
||||||
|
### From Pydantic Models
|
||||||
|
|
||||||
|
When you create an empty table without data, you must specify the table schema.
|
||||||
|
LanceDB supports creating tables by specifying a PyArrow schema or a specialized
|
||||||
|
Pydantic model called `LanceModel`.
|
||||||
|
|
||||||
|
For example, the following Content model specifies a table with 5 columns:
|
||||||
|
`movie_id`, `vector`, `genres`, `title`, and `imdb_id`. When you create a table, you can
|
||||||
|
pass the class as the value of the `schema` parameter to `create_table`.
|
||||||
|
The `vector` column is a `Vector` type, which is a specialized Pydantic type that
|
||||||
|
can be configured with the vector dimensions. It is also important to note that
|
||||||
|
LanceDB only understands subclasses of `lancedb.pydantic.LanceModel`
|
||||||
|
(which itself derives from `pydantic.BaseModel`).
|
||||||
|
|
||||||
|
```python
|
||||||
|
from lancedb.pydantic import Vector, LanceModel
|
||||||
|
|
||||||
|
class Content(LanceModel):
|
||||||
|
movie_id: int
|
||||||
|
vector: Vector(128)
|
||||||
|
genres: str
|
||||||
|
title: str
|
||||||
|
imdb_id: int
|
||||||
|
|
||||||
|
@property
|
||||||
|
def imdb_url(self) -> str:
|
||||||
|
return f"https://www.imdb.com/title/tt{self.imdb_id}"
|
||||||
|
|
||||||
|
import pyarrow as pa
|
||||||
|
db = lancedb.connect("~/.lancedb")
|
||||||
|
table_name = "movielens_small"
|
||||||
|
table = db.create_table(table_name, schema=Content)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Nested schemas
|
||||||
|
|
||||||
|
Sometimes your data model may contain nested objects.
|
||||||
|
For example, you may want to store the document string
|
||||||
|
and the document soure name as a nested Document object:
|
||||||
|
|
||||||
|
```python
|
||||||
|
class Document(BaseModel):
|
||||||
|
content: str
|
||||||
|
source: str
|
||||||
|
```
|
||||||
|
|
||||||
|
This can be used as the type of a LanceDB table column:
|
||||||
|
|
||||||
|
```python
|
||||||
|
class NestedSchema(LanceModel):
|
||||||
|
id: str
|
||||||
|
vector: Vector(1536)
|
||||||
|
document: Document
|
||||||
|
|
||||||
|
tbl = db.create_table("nested_table", schema=NestedSchema, mode="overwrite")
|
||||||
|
```
|
||||||
|
|
||||||
|
This creates a struct column called "document" that has two subfields
|
||||||
|
called "content" and "source":
|
||||||
|
|
||||||
|
```
|
||||||
|
In [28]: tbl.schema
|
||||||
|
Out[28]:
|
||||||
|
id: string not null
|
||||||
|
vector: fixed_size_list<item: float>[1536] not null
|
||||||
|
child 0, item: float
|
||||||
|
document: struct<content: string not null, source: string not null> not null
|
||||||
|
child 0, content: string not null
|
||||||
|
child 1, source: string not null
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Validators
|
||||||
|
|
||||||
|
Note that neither Pydantic nor PyArrow automatically validates that input data
|
||||||
|
is of the correct timezone, but this is easy to add as a custom field validator:
|
||||||
|
|
||||||
|
```python
|
||||||
|
from datetime import datetime
|
||||||
|
from zoneinfo import ZoneInfo
|
||||||
|
|
||||||
|
from lancedb.pydantic import LanceModel
|
||||||
|
from pydantic import Field, field_validator, ValidationError, ValidationInfo
|
||||||
|
|
||||||
|
tzname = "America/New_York"
|
||||||
|
tz = ZoneInfo(tzname)
|
||||||
|
|
||||||
|
class TestModel(LanceModel):
|
||||||
|
dt_with_tz: datetime = Field(json_schema_extra={"tz": tzname})
|
||||||
|
|
||||||
|
@field_validator('dt_with_tz')
|
||||||
|
@classmethod
|
||||||
|
def tz_must_match(cls, dt: datetime) -> datetime:
|
||||||
|
assert dt.tzinfo == tz
|
||||||
|
return dt
|
||||||
|
|
||||||
|
ok = TestModel(dt_with_tz=datetime.now(tz))
|
||||||
|
|
||||||
|
try:
|
||||||
|
TestModel(dt_with_tz=datetime.now(ZoneInfo("Asia/Shanghai")))
|
||||||
|
assert 0 == 1, "this should raise ValidationError"
|
||||||
|
except ValidationError:
|
||||||
|
print("A ValidationError was raised.")
|
||||||
|
pass
|
||||||
|
```
|
||||||
|
|
||||||
|
When you run this code it should print "A ValidationError was raised."
|
||||||
|
|
||||||
|
#### Pydantic custom types
|
||||||
|
|
||||||
|
LanceDB does NOT yet support converting pydantic custom types. If this is something you need,
|
||||||
|
please file a feature request on the [LanceDB Github repo](https://github.com/lancedb/lancedb/issues/new).
|
||||||
|
|
||||||
|
### Using Iterators / Writing Large Datasets
|
||||||
|
|
||||||
|
It is recommended to use iterators to add large datasets in batches when creating your table in one go. This does not create multiple versions of your dataset unlike manually adding batches using `table.add()`
|
||||||
|
|
||||||
|
LanceDB additionally supports PyArrow's `RecordBatch` Iterators or other generators producing supported data types.
|
||||||
|
|
||||||
|
Here's an example using using `RecordBatch` iterator for creating tables.
|
||||||
|
|
||||||
|
```python
|
||||||
|
import pyarrow as pa
|
||||||
|
|
||||||
|
def make_batches():
|
||||||
|
for i in range(5):
|
||||||
|
yield pa.RecordBatch.from_arrays(
|
||||||
|
[
|
||||||
|
pa.array([[3.1, 4.1, 5.1, 6.1], [5.9, 26.5, 4.7, 32.8]],
|
||||||
|
pa.list_(pa.float32(), 4)),
|
||||||
|
pa.array(["foo", "bar"]),
|
||||||
|
pa.array([10.0, 20.0]),
|
||||||
|
],
|
||||||
|
["vector", "item", "price"],
|
||||||
|
)
|
||||||
|
|
||||||
|
schema = pa.schema([
|
||||||
|
pa.field("vector", pa.list_(pa.float32(), 4)),
|
||||||
|
pa.field("item", pa.utf8()),
|
||||||
|
pa.field("price", pa.float32()),
|
||||||
|
])
|
||||||
|
|
||||||
|
db.create_table("batched_tale", make_batches(), schema=schema)
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also use iterators of other types like Pandas DataFrame or Pylists directly in the above example.
|
||||||
|
|
||||||
|
## Open existing tables
|
||||||
|
|
||||||
|
=== "Python"
|
||||||
|
If you forget the name of your table, you can always get a listing of all table names.
|
||||||
|
|
||||||
|
```python
|
||||||
|
print(db.table_names())
|
||||||
|
```
|
||||||
|
|
||||||
|
Then, you can open any existing tables.
|
||||||
|
|
||||||
|
```python
|
||||||
|
tbl = db.open_table("my_table")
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "JavaScript"
|
||||||
|
If you forget the name of your table, you can always get a listing of all table names.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
console.log(await db.tableNames());
|
||||||
|
```
|
||||||
|
|
||||||
|
Then, you can open any existing tables.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const tbl = await db.openTable("my_table");
|
||||||
|
```
|
||||||
|
|
||||||
|
## Creating empty table
|
||||||
|
|
||||||
|
=== "Python"
|
||||||
|
In Python, you can create an empty table for scenarios where you want to add data to the table later. An example would be when you want to collect data from a stream/external file and then add it to a table in batches.
|
||||||
|
|
||||||
|
```python
|
||||||
|
|
||||||
|
An empty table can be initialized via a PyArrow schema.
|
||||||
|
|
||||||
|
```python
|
||||||
|
import lancedb
|
||||||
|
import pyarrow as pa
|
||||||
|
|
||||||
|
schema = pa.schema(
|
||||||
|
[
|
||||||
|
pa.field("vector", pa.list_(pa.float32(), 2)),
|
||||||
|
pa.field("item", pa.string()),
|
||||||
|
pa.field("price", pa.float32()),
|
||||||
|
])
|
||||||
|
tbl = db.create_table("empty_table_add", schema=schema)
|
||||||
|
```
|
||||||
|
|
||||||
|
Alternatively, you can also use Pydantic to specify the schema for the empty table. Note that we do not
|
||||||
|
directly import `pydantic` but instead use `lancedb.pydantic` which is a subclass of `pydantic.BaseModel`
|
||||||
|
that has been extended to support LanceDB specific types like `Vector`.
|
||||||
|
|
||||||
|
```python
|
||||||
|
import lancedb
|
||||||
|
from lancedb.pydantic import LanceModel, vector
|
||||||
|
|
||||||
|
class Item(LanceModel):
|
||||||
|
vector: Vector(2)
|
||||||
|
item: str
|
||||||
|
price: float
|
||||||
|
|
||||||
|
tbl = db.create_table("empty_table_add", schema=Item.to_arrow_schema())
|
||||||
|
```
|
||||||
|
|
||||||
|
Once the empty table has been created, you can add data to it via the various methods listed in the [Adding to a table](#adding-to-a-table) section.
|
||||||
|
|
||||||
|
## Adding to a table
|
||||||
|
|
||||||
|
After a table has been created, you can always add more data to it using the various methods available.
|
||||||
|
|
||||||
|
=== "Python"
|
||||||
|
You can add any of the valid data structures accepted by LanceDB table, i.e, `dict`, `list[dict]`, `pd.DataFrame`, or `Iterator[pa.RecordBatch]`. Below are some examples.
|
||||||
|
|
||||||
|
### Add a Pandas DataFrame
|
||||||
|
|
||||||
|
```python
|
||||||
|
df = pd.DataFrame({
|
||||||
|
"vector": [[1.3, 1.4], [9.5, 56.2]], "item": ["banana", "apple"], "price": [5.0, 7.0]
|
||||||
|
})
|
||||||
|
tbl.add(df)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Add a Polars DataFrame
|
||||||
|
|
||||||
|
```python
|
||||||
|
df = pl.DataFrame({
|
||||||
|
"vector": [[1.3, 1.4], [9.5, 56.2]], "item": ["banana", "apple"], "price": [5.0, 7.0]
|
||||||
|
})
|
||||||
|
tbl.add(df)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Add an Iterator
|
||||||
|
|
||||||
|
You can also add a large dataset batch in one go using Iterator of any supported data types.
|
||||||
|
|
||||||
|
```python
|
||||||
|
def make_batches():
|
||||||
|
for i in range(5):
|
||||||
|
yield [
|
||||||
|
{"vector": [3.1, 4.1], "item": "peach", "price": 6.0},
|
||||||
|
{"vector": [5.9, 26.5], "item": "pear", "price": 5.0}
|
||||||
|
]
|
||||||
|
tbl.add(make_batches())
|
||||||
|
```
|
||||||
|
|
||||||
|
### Add a PyArrow table
|
||||||
|
|
||||||
|
If you have data coming in as a PyArrow table, you can add it directly to the LanceDB table.
|
||||||
|
|
||||||
|
```python
|
||||||
|
pa_table = pa.Table.from_arrays(
|
||||||
|
[
|
||||||
|
pa.array([[9.1, 6.7], [9.9, 31.2]],
|
||||||
|
pa.list_(pa.float32(), 2)),
|
||||||
|
pa.array(["mango", "orange"]),
|
||||||
|
pa.array([7.0, 4.0]),
|
||||||
|
],
|
||||||
|
["vector", "item", "price"],
|
||||||
|
)
|
||||||
|
|
||||||
|
tbl.add(pa_table)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Add a Pydantic Model
|
||||||
|
|
||||||
|
Assuming that a table has been created with the correct schema as shown [above](#creating-empty-table), you can add data items that are valid Pydantic models to the table.
|
||||||
|
|
||||||
|
```python
|
||||||
|
pydantic_model_items = [
|
||||||
|
Item(vector=[8.1, 4.7], item="pineapple", price=10.0),
|
||||||
|
Item(vector=[6.9, 9.3], item="avocado", price=9.0)
|
||||||
|
]
|
||||||
|
|
||||||
|
tbl.add(pydantic_model_items)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
=== "JavaScript"
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
await tbl.add(
|
||||||
|
[
|
||||||
|
{vector: [1.3, 1.4], item: "fizz", price: 100.0},
|
||||||
|
{vector: [9.5, 56.2], item: "buzz", price: 200.0}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Deleting from a table
|
||||||
|
|
||||||
|
Use the `delete()` method on tables to delete rows from a table. To choose which rows to delete, provide a filter that matches on the metadata columns. This can delete any number of rows that match the filter.
|
||||||
|
|
||||||
|
=== "Python"
|
||||||
|
|
||||||
|
```python
|
||||||
|
tbl.delete('item = "fizz"')
|
||||||
|
```
|
||||||
|
|
||||||
|
### Deleting row with specific column value
|
||||||
|
|
||||||
|
```python
|
||||||
|
import lancedb
|
||||||
|
|
||||||
|
data = [{"x": 1, "vector": [1, 2]},
|
||||||
|
{"x": 2, "vector": [3, 4]},
|
||||||
|
{"x": 3, "vector": [5, 6]}]
|
||||||
|
db = lancedb.connect("./.lancedb")
|
||||||
|
table = db.create_table("my_table", data)
|
||||||
|
table.to_pandas()
|
||||||
|
# x vector
|
||||||
|
# 0 1 [1.0, 2.0]
|
||||||
|
# 1 2 [3.0, 4.0]
|
||||||
|
# 2 3 [5.0, 6.0]
|
||||||
|
|
||||||
|
table.delete("x = 2")
|
||||||
|
table.to_pandas()
|
||||||
|
# x vector
|
||||||
|
# 0 1 [1.0, 2.0]
|
||||||
|
# 1 3 [5.0, 6.0]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Delete from a list of values
|
||||||
|
|
||||||
|
```python
|
||||||
|
to_remove = [1, 5]
|
||||||
|
to_remove = ", ".join(str(v) for v in to_remove)
|
||||||
|
|
||||||
|
table.delete(f"x IN ({to_remove})")
|
||||||
|
table.to_pandas()
|
||||||
|
# x vector
|
||||||
|
# 0 3 [5.0, 6.0]
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "JavaScript"
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
await tbl.delete('item = "fizz"')
|
||||||
|
```
|
||||||
|
|
||||||
|
### Deleting row with specific column value
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const con = await lancedb.connect("./.lancedb")
|
||||||
|
const data = [
|
||||||
|
{id: 1, vector: [1, 2]},
|
||||||
|
{id: 2, vector: [3, 4]},
|
||||||
|
{id: 3, vector: [5, 6]},
|
||||||
|
];
|
||||||
|
const tbl = await con.createTable("my_table", data)
|
||||||
|
await tbl.delete("id = 2")
|
||||||
|
await tbl.countRows() // Returns 2
|
||||||
|
```
|
||||||
|
|
||||||
|
### Delete from a list of values
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const to_remove = [1, 5];
|
||||||
|
await tbl.delete(`id IN (${to_remove.join(",")})`)
|
||||||
|
await tbl.countRows() // Returns 1
|
||||||
|
```
|
||||||
|
|
||||||
|
## Updating a table
|
||||||
|
|
||||||
|
This can be used to update zero to all rows depending on how many rows match the where clause. The update queries follow the form of a SQL UPDATE statement. The `where` parameter is a SQL filter that matches on the metadata columns. The `values` or `values_sql` parameters are used to provide the new values for the columns.
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
|---|---|---|
|
||||||
|
| `where` | `str` | The SQL where clause to use when updating rows. For example, `'x = 2'` or `'x IN (1, 2, 3)'`. The filter must not be empty, or it will error. |
|
||||||
|
| `values` | `dict` | The values to update. The keys are the column names and the values are the values to set. |
|
||||||
|
| `values_sql` | `dict` | The values to update. The keys are the column names and the values are the SQL expressions to set. For example, `{'x': 'x + 1'}` will increment the value of the `x` column by 1. |
|
||||||
|
|
||||||
|
!!! info "SQL syntax"
|
||||||
|
|
||||||
|
See [SQL filters](../sql.md) for more information on the supported SQL syntax.
|
||||||
|
|
||||||
|
!!! warning "Warning"
|
||||||
|
|
||||||
|
Updating nested columns is not yet supported.
|
||||||
|
|
||||||
|
=== "Python"
|
||||||
|
|
||||||
|
API Reference: [lancedb.table.Table.update][]
|
||||||
|
|
||||||
|
```python
|
||||||
|
import lancedb
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
# Create a lancedb connection
|
||||||
|
db = lancedb.connect("./.lancedb")
|
||||||
|
|
||||||
|
# Create a table from a pandas DataFrame
|
||||||
|
data = pd.DataFrame({"x": [1, 2, 3], "vector": [[1, 2], [3, 4], [5, 6]]})
|
||||||
|
table = db.create_table("my_table", data)
|
||||||
|
|
||||||
|
# Update the table where x = 2
|
||||||
|
table.update(where="x = 2", values={"vector": [10, 10]})
|
||||||
|
|
||||||
|
# Get the updated table as a pandas DataFrame
|
||||||
|
df = table.to_pandas()
|
||||||
|
|
||||||
|
# Print the DataFrame
|
||||||
|
print(df)
|
||||||
|
```
|
||||||
|
|
||||||
|
Output
|
||||||
|
```shell
|
||||||
|
x vector
|
||||||
|
0 1 [1.0, 2.0]
|
||||||
|
1 3 [5.0, 6.0]
|
||||||
|
2 2 [10.0, 10.0]
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "JavaScript/Typescript"
|
||||||
|
|
||||||
|
API Reference: [vectordb.Table.update](../javascript/interfaces/Table.md/#update)
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const lancedb = require("vectordb");
|
||||||
|
|
||||||
|
const db = await lancedb.connect("./.lancedb");
|
||||||
|
|
||||||
|
const data = [
|
||||||
|
{x: 1, vector: [1, 2]},
|
||||||
|
{x: 2, vector: [3, 4]},
|
||||||
|
{x: 3, vector: [5, 6]},
|
||||||
|
];
|
||||||
|
const tbl = await db.createTable("my_table", data)
|
||||||
|
|
||||||
|
await tbl.update({ where: "x = 2", values: {vector: [10, 10]} })
|
||||||
|
```
|
||||||
|
|
||||||
|
The `values` parameter is used to provide the new values for the columns as literal values. You can also use the `values_sql` / `valuesSql` parameter to provide SQL expressions for the new values. For example, you can use `values_sql="x + 1"` to increment the value of the `x` column by 1.
|
||||||
|
|
||||||
|
=== "Python"
|
||||||
|
|
||||||
|
```python
|
||||||
|
# Update the table where x = 2
|
||||||
|
table.update(valuesSql={"x": "x + 1"})
|
||||||
|
|
||||||
|
print(table.to_pandas())
|
||||||
|
```
|
||||||
|
|
||||||
|
Output
|
||||||
|
```shell
|
||||||
|
x vector
|
||||||
|
0 2 [1.0, 2.0]
|
||||||
|
1 4 [5.0, 6.0]
|
||||||
|
2 3 [10.0, 10.0]
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "JavaScript/Typescript"
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
await tbl.update({ valuesSql: { x: "x + 1" } })
|
||||||
|
```
|
||||||
|
|
||||||
|
!!! info "Note"
|
||||||
|
|
||||||
|
When rows are updated, they are moved out of the index. The row will still show up in ANN queries, but the query will not be as fast as it would be if the row was in the index. If you update a large proportion of rows, consider rebuilding the index afterwards.
|
||||||
|
|
||||||
|
## What's next?
|
||||||
|
|
||||||
|
Learn the best practices on creating an ANN index and getting the most out of it.
|
||||||
49
docs/src/hybrid_search/eval.md
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
# Hybrid Search
|
||||||
|
|
||||||
|
Hybrid Search is a broad (often misused) term. It can mean anything from combining multiple methods for searching, to applying ranking methods to better sort the results. In this blog, we use the definition of "hybrid search" to mean using a combination of keyword-based and vector search.
|
||||||
|
|
||||||
|
## The challenge of (re)ranking search results
|
||||||
|
Once you have a group of the most relevant search results from multiple search sources, you'd likely standardize the score and rank them accordingly. This process can also be seen as another independent step - reranking.
|
||||||
|
There are two approaches for reranking search results from multiple sources.
|
||||||
|
* <b>Score-based</b>: Calculate final relevance scores based on a weighted linear combination of individual search algorithm scores. Example - Weighted linear combination of semantic search & keyword-based search results.
|
||||||
|
* <b>Relevance-based</b>: Discards the existing scores and calculates the relevance of each search result - query pair. Example - Cross Encoder models
|
||||||
|
|
||||||
|
Even though there are many strategies for reranking search results, none works for all cases. Moreover, evaluating them itself is a challenge. Also, reranking can be dataset, application specific so it's hard to generalize.
|
||||||
|
|
||||||
|
### Example evaluation of hybrid search with Reranking
|
||||||
|
|
||||||
|
Here's some evaluation numbers from experiment comparing these re-rankers on about 800 queries. It is modified version of an evaluation script from [llama-index](https://github.com/run-llama/finetune-embedding/blob/main/evaluate.ipynb) that measures hit-rate at top-k.
|
||||||
|
|
||||||
|
<b> With OpenAI ada2 embedding </b>
|
||||||
|
|
||||||
|
Vector Search baseline - `0.64`
|
||||||
|
|
||||||
|
| Reranker | Top-3 | Top-5 | Top-10 |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| Linear Combination | `0.73` | `0.74` | `0.85` |
|
||||||
|
| Cross Encoder | `0.71` | `0.70` | `0.77` |
|
||||||
|
| Cohere | `0.81` | `0.81` | `0.85` |
|
||||||
|
| ColBERT | `0.68` | `0.68` | `0.73` |
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<img src="https://github.com/AyushExel/assets/assets/15766192/d57b1780-ef27-414c-a5c3-73bee7808a45">
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<b> With OpenAI embedding-v3-small </b>
|
||||||
|
|
||||||
|
Vector Search baseline - `0.59`
|
||||||
|
|
||||||
|
| Reranker | Top-3 | Top-5 | Top-10 |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| Linear Combination | `0.68` | `0.70` | `0.84` |
|
||||||
|
| Cross Encoder | `0.72` | `0.72` | `0.79` |
|
||||||
|
| Cohere | `0.79` | `0.79` | `0.84` |
|
||||||
|
| ColBERT | `0.70` | `0.70` | `0.76` |
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<img src="https://github.com/AyushExel/assets/assets/15766192/259adfd2-6ec6-4df6-a77d-1456598970dd">
|
||||||
|
</p>
|
||||||
|
|
||||||
|
### Conclusion
|
||||||
|
|
||||||
|
The results show that the reranking methods are able to improve the search results. However, the improvement is not consistent across all rerankers. The choice of reranker depends on the dataset and the application. It is also important to note that the reranking methods are not a replacement for the search methods. They are complementary and should be used together to get the best results. The speed to recall tradeoff is also an important factor to consider when choosing the reranker.
|
||||||
242
docs/src/hybrid_search/hybrid_search.md
Normal file
@@ -0,0 +1,242 @@
|
|||||||
|
# Hybrid Search
|
||||||
|
|
||||||
|
LanceDB supports both semantic and keyword-based search (also termed full-text search, or FTS). In real world applications, it is often useful to combine these two approaches to get the best best results. For example, you may want to search for a document that is semantically similar to a query document, but also contains a specific keyword. This is an example of *hybrid search*, a search algorithm that combines multiple search techniques.
|
||||||
|
|
||||||
|
## Hybrid search in LanceDB
|
||||||
|
You can perform hybrid search in LanceDB by combining the results of semantic and full-text search via a reranking algorithm of your choice. LanceDB provides multiple rerankers out of the box. However, you can always write a custom reranker if your use case need more sophisticated logic .
|
||||||
|
|
||||||
|
```python
|
||||||
|
import os
|
||||||
|
|
||||||
|
import lancedb
|
||||||
|
import openai
|
||||||
|
from lancedb.embeddings import get_registry
|
||||||
|
from lancedb.pydantic import LanceModel, Vector
|
||||||
|
|
||||||
|
db = lancedb.connect("~/.lancedb")
|
||||||
|
|
||||||
|
# Ingest embedding function in LanceDB table
|
||||||
|
# Configuring the environment variable OPENAI_API_KEY
|
||||||
|
if "OPENAI_API_KEY" not in os.environ:
|
||||||
|
# OR set the key here as a variable
|
||||||
|
openai.api_key = "sk-..."
|
||||||
|
embeddings = get_registry().get("openai").create()
|
||||||
|
|
||||||
|
class Documents(LanceModel):
|
||||||
|
vector: Vector(embeddings.ndims()) = embeddings.VectorField()
|
||||||
|
text: str = embeddings.SourceField()
|
||||||
|
|
||||||
|
table = db.create_table("documents", schema=Documents)
|
||||||
|
|
||||||
|
data = [
|
||||||
|
{ "text": "rebel spaceships striking from a hidden base"},
|
||||||
|
{ "text": "have won their first victory against the evil Galactic Empire"},
|
||||||
|
{ "text": "during the battle rebel spies managed to steal secret plans"},
|
||||||
|
{ "text": "to the Empire's ultimate weapon the Death Star"}
|
||||||
|
]
|
||||||
|
|
||||||
|
# ingest docs with auto-vectorization
|
||||||
|
table.add(data)
|
||||||
|
|
||||||
|
# Create a fts index before the hybrid search
|
||||||
|
table.create_fts_index("text")
|
||||||
|
# hybrid search with default re-ranker
|
||||||
|
results = table.search("flower moon", query_type="hybrid").to_pandas()
|
||||||
|
```
|
||||||
|
|
||||||
|
By default, LanceDB uses `LinearCombinationReranker(weight=0.7)` to combine and rerank the results of semantic and full-text search. You can customize the hyperparameters as needed or write your own custom reranker. Here's how you can use any of the available rerankers:
|
||||||
|
|
||||||
|
|
||||||
|
### `rerank()` arguments
|
||||||
|
* `normalize`: `str`, default `"score"`:
|
||||||
|
The method to normalize the scores. Can be "rank" or "score". If "rank", the scores are converted to ranks and then normalized. If "score", the scores are normalized directly.
|
||||||
|
* `reranker`: `Reranker`, default `LinearCombinationReranker(weight=0.7)`.
|
||||||
|
The reranker to use. If not specified, the default reranker is used.
|
||||||
|
|
||||||
|
|
||||||
|
## Available Rerankers
|
||||||
|
LanceDB provides a number of re-rankers out of the box. You can use any of these re-rankers by passing them to the `rerank()` method. Here's a list of available re-rankers:
|
||||||
|
|
||||||
|
### Linear Combination Reranker
|
||||||
|
This is the default re-ranker used by LanceDB. It combines the results of semantic and full-text search using a linear combination of the scores. The weights for the linear combination can be specified. It defaults to 0.7, i.e, 70% weight for semantic search and 30% weight for full-text search.
|
||||||
|
|
||||||
|
|
||||||
|
```python
|
||||||
|
from lancedb.rerankers import LinearCombinationReranker
|
||||||
|
|
||||||
|
reranker = LinearCombinationReranker(weight=0.3) # Use 0.3 as the weight for vector search
|
||||||
|
|
||||||
|
results = table.search("rebel", query_type="hybrid").rerank(reranker=reranker).to_pandas()
|
||||||
|
```
|
||||||
|
|
||||||
|
### Arguments
|
||||||
|
----------------
|
||||||
|
* `weight`: `float`, default `0.7`:
|
||||||
|
The weight to use for the semantic search score. The weight for the full-text search score is `1 - weights`.
|
||||||
|
* `fill`: `float`, default `1.0`:
|
||||||
|
The score to give to results that are only in one of the two result sets.This is treated as penalty, so a higher value means a lower score.
|
||||||
|
TODO: We should just hardcode this-- its pretty confusing as we invert scores to calculate final score
|
||||||
|
* `return_score` : str, default `"relevance"`
|
||||||
|
options are "relevance" or "all"
|
||||||
|
The type of score to return. If "relevance", will return only the `_relevance_score. If "all", will return all scores from the vector and FTS search along with the relevance score.
|
||||||
|
|
||||||
|
### Cohere Reranker
|
||||||
|
This re-ranker uses the [Cohere](https://cohere.ai/) API to combine the results of semantic and full-text search. You can use this re-ranker by passing `CohereReranker()` to the `rerank()` method. Note that you'll need to set the `COHERE_API_KEY` environment variable to use this re-ranker.
|
||||||
|
|
||||||
|
```python
|
||||||
|
from lancedb.rerankers import CohereReranker
|
||||||
|
|
||||||
|
reranker = CohereReranker()
|
||||||
|
|
||||||
|
results = table.search("vampire weekend", query_type="hybrid").rerank(reranker=reranker).to_pandas()
|
||||||
|
```
|
||||||
|
|
||||||
|
### Arguments
|
||||||
|
----------------
|
||||||
|
* `model_name` : str, default `"rerank-english-v2.0"`
|
||||||
|
The name of the cross encoder model to use. Available cohere models are:
|
||||||
|
- rerank-english-v2.0
|
||||||
|
- rerank-multilingual-v2.0
|
||||||
|
* `column` : str, default `"text"`
|
||||||
|
The name of the column to use as input to the cross encoder model.
|
||||||
|
* `top_n` : str, default `None`
|
||||||
|
The number of results to return. If None, will return all results.
|
||||||
|
|
||||||
|
!!! Note
|
||||||
|
Only returns `_relevance_score`. Does not support `return_score = "all"`.
|
||||||
|
|
||||||
|
### Cross Encoder Reranker
|
||||||
|
This reranker uses the [Sentence Transformers](https://www.sbert.net/) library to combine the results of semantic and full-text search. You can use it by passing `CrossEncoderReranker()` to the `rerank()` method.
|
||||||
|
|
||||||
|
```python
|
||||||
|
from lancedb.rerankers import CrossEncoderReranker
|
||||||
|
|
||||||
|
reranker = CrossEncoderReranker()
|
||||||
|
|
||||||
|
results = table.search("harmony hall", query_type="hybrid").rerank(reranker=reranker).to_pandas()
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### Arguments
|
||||||
|
----------------
|
||||||
|
* `model` : str, default `"cross-encoder/ms-marco-TinyBERT-L-6"`
|
||||||
|
The name of the cross encoder model to use. Available cross encoder models can be found [here](https://www.sbert.net/docs/pretrained_cross-encoders.html)
|
||||||
|
* `column` : str, default `"text"`
|
||||||
|
The name of the column to use as input to the cross encoder model.
|
||||||
|
* `device` : str, default `None`
|
||||||
|
The device to use for the cross encoder model. If None, will use "cuda" if available, otherwise "cpu".
|
||||||
|
|
||||||
|
!!! Note
|
||||||
|
Only returns `_relevance_score`. Does not support `return_score = "all"`.
|
||||||
|
|
||||||
|
|
||||||
|
### ColBERT Reranker
|
||||||
|
This reranker uses the ColBERT model to combine the results of semantic and full-text search. You can use it by passing `ColbertrReranker()` to the `rerank()` method.
|
||||||
|
|
||||||
|
ColBERT reranker model calculates relevance of given docs against the query and don't take existing fts and vector search scores into account, so it currently only supports `return_score="relevance"`. By default, it looks for `text` column to rerank the results. But you can specify the column name to use as input to the cross encoder model as described below.
|
||||||
|
|
||||||
|
```python
|
||||||
|
from lancedb.rerankers import ColbertReranker
|
||||||
|
|
||||||
|
reranker = ColbertReranker()
|
||||||
|
|
||||||
|
results = table.search("harmony hall", query_type="hybrid").rerank(reranker=reranker).to_pandas()
|
||||||
|
```
|
||||||
|
|
||||||
|
### Arguments
|
||||||
|
----------------
|
||||||
|
* `model_name` : `str`, default `"colbert-ir/colbertv2.0"`
|
||||||
|
The name of the cross encoder model to use.
|
||||||
|
* `column` : `str`, default `"text"`
|
||||||
|
The name of the column to use as input to the cross encoder model.
|
||||||
|
* `return_score` : `str`, default `"relevance"`
|
||||||
|
options are `"relevance"` or `"all"`. Only `"relevance"` is supported for now.
|
||||||
|
|
||||||
|
!!! Note
|
||||||
|
Only returns `_relevance_score`. Does not support `return_score = "all"`.
|
||||||
|
|
||||||
|
### OpenAI Reranker
|
||||||
|
This reranker uses the OpenAI API to combine the results of semantic and full-text search. You can use it by passing `OpenaiReranker()` to the `rerank()` method.
|
||||||
|
|
||||||
|
!!! Note
|
||||||
|
This prompts chat model to rerank results which is not a dedicated reranker model. This should be treated as experimental.
|
||||||
|
|
||||||
|
!!! Tip
|
||||||
|
- You might run out of token limit so set the search `limits` based on your token limit.
|
||||||
|
- It is recommended to use gpt-4-turbo-preview, the default model, older models might lead to undesired behaviour
|
||||||
|
|
||||||
|
```python
|
||||||
|
from lancedb.rerankers import OpenaiReranker
|
||||||
|
|
||||||
|
reranker = OpenaiReranker()
|
||||||
|
|
||||||
|
results = table.search("harmony hall", query_type="hybrid").rerank(reranker=reranker).to_pandas()
|
||||||
|
```
|
||||||
|
|
||||||
|
### Arguments
|
||||||
|
----------------
|
||||||
|
* `model_name` : `str`, default `"gpt-4-turbo-preview"`
|
||||||
|
The name of the cross encoder model to use.
|
||||||
|
* `column` : `str`, default `"text"`
|
||||||
|
The name of the column to use as input to the cross encoder model.
|
||||||
|
* `return_score` : `str`, default `"relevance"`
|
||||||
|
options are "relevance" or "all". Only "relevance" is supported for now.
|
||||||
|
* `api_key` : `str`, default `None`
|
||||||
|
The API key to use. If None, will use the OPENAI_API_KEY environment variable.
|
||||||
|
|
||||||
|
|
||||||
|
## Building Custom Rerankers
|
||||||
|
You can build your own custom reranker by subclassing the `Reranker` class and implementing the `rerank_hybrid()` method. Here's an example of a custom reranker that combines the results of semantic and full-text search using a linear combination of the scores.
|
||||||
|
|
||||||
|
The `Reranker` base interface comes with a `merge_results()` method that can be used to combine the results of semantic and full-text search. This is a vanilla merging algorithm that simply concatenates the results and removes the duplicates without taking the scores into consideration. It only keeps the first copy of the row encountered. This works well in cases that don't require the scores of semantic and full-text search to combine the results. If you want to use the scores or want to support `return_score="all"`, you'll need to implement your own merging algorithm.
|
||||||
|
|
||||||
|
```python
|
||||||
|
|
||||||
|
from lancedb.rerankers import Reranker
|
||||||
|
import pyarrow as pa
|
||||||
|
|
||||||
|
class MyReranker(Reranker):
|
||||||
|
def __init__(self, param1, param2, ..., return_score="relevance"):
|
||||||
|
super().__init__(return_score)
|
||||||
|
self.param1 = param1
|
||||||
|
self.param2 = param2
|
||||||
|
|
||||||
|
def rerank_hybrid(self, query: str, vector_results: pa.Table, fts_results: pa.Table):
|
||||||
|
# Use the built-in merging function
|
||||||
|
combined_result = self.merge_results(vector_results, fts_results)
|
||||||
|
|
||||||
|
# Do something with the combined results
|
||||||
|
# ...
|
||||||
|
|
||||||
|
# Return the combined results
|
||||||
|
return combined_result
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Example of a Custom Reranker
|
||||||
|
For the sake of simplicity let's build custom reranker that just enchances the Cohere Reranker by accepting a filter query, and accept other CohereReranker params as kwags.
|
||||||
|
|
||||||
|
```python
|
||||||
|
|
||||||
|
from typing import List, Union
|
||||||
|
import pandas as pd
|
||||||
|
from lancedb.rerankers import CohereReranker
|
||||||
|
|
||||||
|
class MofidifiedCohereReranker(CohereReranker):
|
||||||
|
def __init__(self, filters: Union[str, List[str]], **kwargs):
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
filters = filters if isinstance(filters, list) else [filters]
|
||||||
|
self.filters = filters
|
||||||
|
|
||||||
|
def rerank_hybrid(self, query: str, vector_results: pa.Table, fts_results: pa.Table)-> pa.Table:
|
||||||
|
combined_result = super().rerank_hybrid(query, vector_results, fts_results)
|
||||||
|
df = combined_result.to_pandas()
|
||||||
|
for filter in self.filters:
|
||||||
|
df = df.query("not text.str.contains(@filter)")
|
||||||
|
|
||||||
|
return pa.Table.from_pandas(df)
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
!!! tip
|
||||||
|
The `vector_results` and `fts_results` are pyarrow tables. You can convert them to pandas dataframes using `to_pandas()` method and perform any operations you want. After you are done, you can convert the dataframe back to pyarrow table using `pa.Table.from_pandas()` method and return it.
|
||||||
@@ -1,72 +1,56 @@
|
|||||||
# Welcome to LanceDB's Documentation
|
# LanceDB
|
||||||
|
|
||||||
LanceDB is an open-source database for vector-search built with persistent storage, which greatly simplifies retrevial, filtering and management of embeddings.
|
LanceDB is an open-source vector database for AI that's designed to store, manage, query and retrieve embeddings on large-scale multi-modal data. The core of LanceDB is written in Rust 🦀 and is built on top of [Lance](https://github.com/lancedb/lance), an open-source columnar data format designed for performant ML workloads and fast random access.
|
||||||
|
|
||||||
The key features of LanceDB include:
|
Both the database and the underlying data format are designed from the ground up to be **easy-to-use**, **scalable** and **cost-effective**.
|
||||||
|
|
||||||
* Production-scale vector search with no servers to manage.
|

|
||||||
|
|
||||||
* Store, query and filter vectors, metadata and multi-modal data (text, images, videos, point clouds, and more).
|
## Truly multi-modal
|
||||||
|
|
||||||
* Support for vector similarity search, full-text search and SQL.
|
Most existing vector databases that store and query just the embeddings and their metadata. The actual data is stored elsewhere, requiring you to manage their storage and versioning separately.
|
||||||
|
|
||||||
* Native Python and Javascript/Typescript support.
|
LanceDB supports storage of the *actual data itself*, alongside the embeddings and metadata. You can persist your images, videos, text documents, audio files and more in the Lance format, which provides automatic data versioning and blazing fast retrievals and filtering via LanceDB.
|
||||||
|
|
||||||
* Zero-copy, automatic versioning, manage versions of your data without needing extra infrastructure.
|
## Open-source and cloud solutions
|
||||||
|
|
||||||
* Ecosystem integrations with [LangChain 🦜️🔗](https://python.langchain.com/en/latest/modules/indexes/vectorstores/examples/lancedb.html), [LlamaIndex 🦙](https://gpt-index.readthedocs.io/en/latest/examples/vector_stores/LanceDBIndexDemo.html), Apache-Arrow, Pandas, Polars, DuckDB and more on the way.
|
LanceDB is available in two flavors: **OSS** and **Cloud**.
|
||||||
|
|
||||||
LanceDB's core is written in Rust 🦀 and is built using <a href="https://github.com/lancedb/lance">Lance</a>, an open-source columnar format designed for performant ML workloads.
|
LanceDB **OSS** is an **open-source**, batteries-included embedded vector database that you can run on your own infrastructure. "Embedded" means that it runs *in-process*, making it incredibly simple to self-host your own AI retrieval workflows for RAG and more. No servers, no hassle.
|
||||||
|
|
||||||
## Quick Start
|
LanceDB **Cloud** is a SaaS (software-as-a-service) solution that runs serverless in the cloud, making the storage clearly separated from compute. It's designed to be cost-effective and highly scalable without breaking the bank. LanceDB Cloud is currently in private beta with general availability coming soon, but you can apply for early access with the private beta release by signing up below.
|
||||||
|
|
||||||
=== "Python"
|
[Try out LanceDB Cloud](https://noteforms.com/forms/lancedb-mailing-list-cloud-kty1o5?notionforms=1&utm_source=notionforms){ .md-button .md-button--primary }
|
||||||
```shell
|
|
||||||
pip install lancedb
|
|
||||||
```
|
|
||||||
|
|
||||||
```python
|
## Why use LanceDB?
|
||||||
import lancedb
|
|
||||||
|
|
||||||
uri = "data/sample-lancedb"
|
* Embedded (OSS) and serverless (Cloud) - no need to manage servers
|
||||||
db = lancedb.connect(uri)
|
|
||||||
table = db.create_table("my_table",
|
|
||||||
data=[{"vector": [3.1, 4.1], "item": "foo", "price": 10.0},
|
|
||||||
{"vector": [5.9, 26.5], "item": "bar", "price": 20.0}])
|
|
||||||
result = table.search([100, 100]).limit(2).to_df()
|
|
||||||
```
|
|
||||||
|
|
||||||
=== "Javascript"
|
* Fast production-scale vector similarity, full-text & hybrid search and a SQL query interface (via [DataFusion](https://github.com/apache/arrow-datafusion))
|
||||||
```shell
|
|
||||||
npm install vectordb
|
|
||||||
```
|
|
||||||
|
|
||||||
```javascript
|
* Native Python and Javascript/Typescript support
|
||||||
const lancedb = require("vectordb");
|
|
||||||
|
|
||||||
const uri = "data/sample-lancedb";
|
* Store, query & manage multi-modal data (text, images, videos, point clouds, etc.), not just the embeddings and metadata
|
||||||
const db = await lancedb.connect(uri);
|
|
||||||
const table = await db.createTable("my_table",
|
|
||||||
[{ id: 1, vector: [3.1, 4.1], item: "foo", price: 10.0 },
|
|
||||||
{ id: 2, vector: [5.9, 26.5], item: "bar", price: 20.0 }])
|
|
||||||
const results = await table.search([100, 100]).limit(2).execute();
|
|
||||||
```
|
|
||||||
|
|
||||||
## Complete Demos (Python)
|
* Tight integration with the [Arrow](https://arrow.apache.org/docs/format/Columnar.html) ecosystem, allowing true zero-copy access in shared memory with SIMD and GPU acceleration
|
||||||
- [YouTube Transcript Search](notebooks/youtube_transcript_search.ipynb)
|
|
||||||
- [Documentation QA Bot using LangChain](notebooks/code_qa_bot.ipynb)
|
|
||||||
- [Multimodal search using CLIP](notebooks/multimodal_search.ipynb)
|
|
||||||
- [Serverless QA Bot with S3 and Lambda](examples/serverless_lancedb_with_s3_and_lambda.md)
|
|
||||||
- [Serverless QA Bot with Modal](examples/serverless_qa_bot_with_modal_and_langchain.md)
|
|
||||||
|
|
||||||
## Complete Demos (JavaScript)
|
* Automatic data versioning to manage versions of your data without needing extra infrastructure
|
||||||
- [YouTube Transcript Search](examples/youtube_transcript_bot_with_nodejs.md)
|
|
||||||
|
|
||||||
## Documentation Quick Links
|
* Disk-based index & storage, allowing for massive scalability without breaking the bank
|
||||||
* [`Basic Operations`](basic.md) - basic functionality of LanceDB.
|
|
||||||
* [`Embedding Functions`](embedding.md) - functions for working with embeddings.
|
* Ingest your favorite data formats directly, like pandas DataFrames, Pydantic objects, Polars (coming soon), and more
|
||||||
* [`Indexing`](ann_indexes.md) - create vector indexes to speed up queries.
|
|
||||||
* [`Full text search`](fts.md) - [EXPERIMENTAL] full-text search API
|
## Documentation guide
|
||||||
* [`Ecosystem Integrations`](python/integration.md) - integrating LanceDB with python data tooling ecosystem.
|
|
||||||
* [`Python API Reference`](python/python.md) - detailed documentation for the LanceDB Python SDK.
|
The following pages go deeper into the internal of LanceDB and how to use it.
|
||||||
* [`Node API Reference`](javascript/modules.md) - detailed documentation for the LanceDB Python SDK.
|
|
||||||
|
* [Quick start](basic.md): Get started with LanceDB and vector DB concepts
|
||||||
|
* [Vector search concepts](concepts/vector_search.md): Understand the basics of vector search
|
||||||
|
* [Working with tables](guides/tables.md): Learn how to work with tables and their associated functions
|
||||||
|
* [Indexing](ann_indexes.md): Understand how to create indexes
|
||||||
|
* [Vector search](search.md): Learn how to perform vector similarity search
|
||||||
|
* [Full-text search](fts.md): Learn how to perform full-text search
|
||||||
|
* [Managing embeddings](embeddings/index.md): Managing embeddings and the embedding functions API in LanceDB
|
||||||
|
* [Ecosystem Integrations](integrations/index.md): Integrate LanceDB with other tools in the data ecosystem
|
||||||
|
* [Python API Reference](python/python.md): Python OSS and Cloud API references
|
||||||
|
* [JavaScript API Reference](javascript/modules.md): JavaScript OSS and Cloud API references
|
||||||
|
|||||||
19
docs/src/integrations/index.md
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Integrations
|
||||||
|
|
||||||
|
LanceDB supports ingesting from and exporting to your favorite data formats across the Python and JavaScript ecosystems.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
## Tools
|
||||||
|
|
||||||
|
LanceDB is integrated with a lot of popular AI tools, with more coming soon.
|
||||||
|
Get started using these examples and quick links.
|
||||||
|
|
||||||
|
| Integrations | |
|
||||||
|
|---|---:|
|
||||||
|
| <h3> LlamaIndex </h3>LlamaIndex is a simple, flexible data framework for connecting custom data sources to large language models. Llama index integrates with LanceDB as the serverless VectorDB. <h3>[Lean More](https://gpt-index.readthedocs.io/en/latest/examples/vector_stores/LanceDBIndexDemo.html) </h3> |<img src="../assets/llama-index.jpg" alt="image" width="150" height="auto">|
|
||||||
|
| <h3>Langchain</h3>Langchain allows building applications with LLMs through composability <h3>[Lean More](https://python.langchain.com/en/latest/modules/indexes/vectorstores/examples/lancedb.html) | <img src="../assets/langchain.png" alt="image" width="150" height="auto">|
|
||||||
|
| <h3>Langchain TS</h3> Javascript bindings for Langchain. It integrates with LanceDB's serverless vectordb allowing you to build powerful AI applications through composibility using only serverless functions. <h3>[Learn More]( https://js.langchain.com/docs/modules/data_connection/vectorstores/integrations/lancedb) | <img src="../assets/langchain.png" alt="image" width="150" height="auto">|
|
||||||
|
| <h3>Voxel51</h3> It is an open source toolkit that enables you to build better computer vision workflows by improving the quality of your datasets and delivering insights about your models.<h3>[Learn More](./voxel51.md) | <img src="../assets/voxel.gif" alt="image" width="150" height="auto">|
|
||||||
|
| <h3>PromptTools</h3> Offers a set of free, open-source tools for testing and experimenting with models, prompts, and configurations. The core idea is to enable developers to evaluate prompts using familiar interfaces like code and notebooks. You can use it to experiment with different configurations of LanceDB, and test how LanceDB integrates with the LLM of your choice.<h3>[Learn More](./prompttools.md) | <img src="../assets/prompttools.jpeg" alt="image" width="150" height="auto">|
|
||||||
9
docs/src/integrations/prompttools.md
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
[PromptTools](https://github.com/hegelai/prompttools) offers a set of free, open-source tools for testing and experimenting with models, prompts, and configurations. The core idea is to enable developers to evaluate prompts using familiar interfaces like code and notebooks. You can use it to experiment with different configurations of LanceDB, and test how LanceDB integrates with the LLM of your choice.
|
||||||
|
<!--
|
||||||
|
[Evaluating Prompts with PromptTools](./examples/prompttools-eval-prompts/) | <a href="https://colab.research.google.com/github/lancedb/vectordb-recipes/blob/main/examples/prompttools-eval-prompts/main.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"></a> -->
|
||||||
|
|
||||||
|
<a href="https://colab.research.google.com/github/lancedb/vectordb-recipes/blob/main/examples/prompttools-eval-prompts/main.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"></a>
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
69
docs/src/integrations/voxel51.md
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
# FiftyOne
|
||||||
|
|
||||||
|
FiftyOne is an open source toolkit for building high-quality datasets and computer vision models. It provides an API to create LanceDB tables and run similarity queries, both programmatically in Python and via point-and-click in the App.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Basic recipe
|
||||||
|
|
||||||
|
The basic workflow shown below uses LanceDB to create a similarity index on your FiftyOne
|
||||||
|
datasets:
|
||||||
|
|
||||||
|
1. Load a dataset into FiftyOne.
|
||||||
|
|
||||||
|
2. Compute embedding vectors for samples or patches in your dataset, or select a model to use to generate embeddings.
|
||||||
|
|
||||||
|
3. Use the `compute_similarity()` method to generate a LanceDB table for the samples or object patches embeddings in a dataset by setting the parameter `backend="lancedb"` and specifying a `brain_key` of your choice.
|
||||||
|
|
||||||
|
4. Use this LanceDB table to query your data with `sort_by_similarity()`.
|
||||||
|
|
||||||
|
5. If desired, delete the table.
|
||||||
|
|
||||||
|
The example below demonstrates this workflow.
|
||||||
|
|
||||||
|
!!! Note
|
||||||
|
|
||||||
|
Install the LanceDB Python client to run the code shown below.
|
||||||
|
```
|
||||||
|
pip install lancedb
|
||||||
|
```
|
||||||
|
|
||||||
|
```python
|
||||||
|
|
||||||
|
import fiftyone as fo
|
||||||
|
import fiftyone.brain as fob
|
||||||
|
import fiftyone.zoo as foz
|
||||||
|
|
||||||
|
# Step 1: Load your data into FiftyOne
|
||||||
|
dataset = foz.load_zoo_dataset("quickstart")
|
||||||
|
|
||||||
|
# Steps 2 and 3: Compute embeddings and create a similarity index
|
||||||
|
lancedb_index = fob.compute_similarity(
|
||||||
|
dataset,
|
||||||
|
model="clip-vit-base32-torch",
|
||||||
|
brain_key="lancedb_index",
|
||||||
|
backend="lancedb",
|
||||||
|
)
|
||||||
|
```
|
||||||
|
Once the similarity index has been generated, we can query our data in FiftyOne
|
||||||
|
by specifying the `brain_key`:
|
||||||
|
|
||||||
|
```python
|
||||||
|
# Step 4: Query your data
|
||||||
|
query = dataset.first().id # query by sample ID
|
||||||
|
view = dataset.sort_by_similarity(
|
||||||
|
query,
|
||||||
|
brain_key="lancedb_index",
|
||||||
|
k=10, # limit to 10 most similar samples
|
||||||
|
)
|
||||||
|
|
||||||
|
# Step 5 (optional): Cleanup
|
||||||
|
|
||||||
|
# Delete the LanceDB table
|
||||||
|
lancedb_index.cleanup()
|
||||||
|
|
||||||
|
# Delete run record from FiftyOne
|
||||||
|
dataset.delete_brain_run("lancedb_index")
|
||||||
|
```
|
||||||
|
|
||||||
|
For a much more in depth walkthrough of the integration, visit the LanceDB x Voxel51 [docs page](https://docs.voxel51.com/integrations/lancedb.html).
|
||||||
@@ -11,8 +11,13 @@ npm install vectordb
|
|||||||
```
|
```
|
||||||
|
|
||||||
This will download the appropriate native library for your platform. We currently
|
This will download the appropriate native library for your platform. We currently
|
||||||
support x86_64 Linux, aarch64 Linux, Intel MacOS, and ARM (M1/M2) MacOS. We do not
|
support:
|
||||||
yet support Windows or musl-based Linux (such as Alpine Linux).
|
|
||||||
|
* Linux (x86_64 and aarch64)
|
||||||
|
* MacOS (Intel and ARM/M1/M2)
|
||||||
|
* Windows (x86_64 only)
|
||||||
|
|
||||||
|
We do not yet support musl-based Linux (such as Alpine Linux) or aarch64 Windows.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
|||||||
41
docs/src/javascript/classes/DefaultWriteOptions.md
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
[vectordb](../README.md) / [Exports](../modules.md) / DefaultWriteOptions
|
||||||
|
|
||||||
|
# Class: DefaultWriteOptions
|
||||||
|
|
||||||
|
Write options when creating a Table.
|
||||||
|
|
||||||
|
## Implements
|
||||||
|
|
||||||
|
- [`WriteOptions`](../interfaces/WriteOptions.md)
|
||||||
|
|
||||||
|
## Table of contents
|
||||||
|
|
||||||
|
### Constructors
|
||||||
|
|
||||||
|
- [constructor](DefaultWriteOptions.md#constructor)
|
||||||
|
|
||||||
|
### Properties
|
||||||
|
|
||||||
|
- [writeMode](DefaultWriteOptions.md#writemode)
|
||||||
|
|
||||||
|
## Constructors
|
||||||
|
|
||||||
|
### constructor
|
||||||
|
|
||||||
|
• **new DefaultWriteOptions**()
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
|
||||||
|
### writeMode
|
||||||
|
|
||||||
|
• **writeMode**: [`WriteMode`](../enums/WriteMode.md) = `WriteMode.Create`
|
||||||
|
|
||||||
|
A [WriteMode](../enums/WriteMode.md) to use on this operation
|
||||||
|
|
||||||
|
#### Implementation of
|
||||||
|
|
||||||
|
[WriteOptions](../interfaces/WriteOptions.md).[writeMode](../interfaces/WriteOptions.md#writemode)
|
||||||
|
|
||||||
|
#### Defined in
|
||||||
|
|
||||||
|
[index.ts:1019](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L1019)
|
||||||
@@ -26,7 +26,7 @@ A connection to a LanceDB database.
|
|||||||
### Methods
|
### Methods
|
||||||
|
|
||||||
- [createTable](LocalConnection.md#createtable)
|
- [createTable](LocalConnection.md#createtable)
|
||||||
- [createTableArrow](LocalConnection.md#createtablearrow)
|
- [createTableImpl](LocalConnection.md#createtableimpl)
|
||||||
- [dropTable](LocalConnection.md#droptable)
|
- [dropTable](LocalConnection.md#droptable)
|
||||||
- [openTable](LocalConnection.md#opentable)
|
- [openTable](LocalConnection.md#opentable)
|
||||||
- [tableNames](LocalConnection.md#tablenames)
|
- [tableNames](LocalConnection.md#tablenames)
|
||||||
@@ -46,7 +46,7 @@ A connection to a LanceDB database.
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:184](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L184)
|
[index.ts:489](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L489)
|
||||||
|
|
||||||
## Properties
|
## Properties
|
||||||
|
|
||||||
@@ -56,17 +56,25 @@ A connection to a LanceDB database.
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:182](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L182)
|
[index.ts:487](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L487)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
### \_options
|
### \_options
|
||||||
|
|
||||||
• `Private` `Readonly` **\_options**: [`ConnectionOptions`](../interfaces/ConnectionOptions.md)
|
• `Private` `Readonly` **\_options**: () => [`ConnectionOptions`](../interfaces/ConnectionOptions.md)
|
||||||
|
|
||||||
|
#### Type declaration
|
||||||
|
|
||||||
|
▸ (): [`ConnectionOptions`](../interfaces/ConnectionOptions.md)
|
||||||
|
|
||||||
|
##### Returns
|
||||||
|
|
||||||
|
[`ConnectionOptions`](../interfaces/ConnectionOptions.md)
|
||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:181](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L181)
|
[index.ts:486](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L486)
|
||||||
|
|
||||||
## Accessors
|
## Accessors
|
||||||
|
|
||||||
@@ -84,27 +92,34 @@ ___
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:189](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L189)
|
[index.ts:494](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L494)
|
||||||
|
|
||||||
## Methods
|
## Methods
|
||||||
|
|
||||||
### createTable
|
### createTable
|
||||||
|
|
||||||
▸ **createTable**(`name`, `data`, `mode?`): `Promise`<[`Table`](../interfaces/Table.md)<`number`[]\>\>
|
▸ **createTable**\<`T`\>(`name`, `data?`, `optsOrEmbedding?`, `opt?`): `Promise`\<[`Table`](../interfaces/Table.md)\<`T`\>\>
|
||||||
|
|
||||||
Creates a new Table and initialize it with new data.
|
Creates a new Table, optionally initializing it with new data.
|
||||||
|
|
||||||
|
#### Type parameters
|
||||||
|
|
||||||
|
| Name |
|
||||||
|
| :------ |
|
||||||
|
| `T` |
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type |
|
||||||
| :------ | :------ | :------ |
|
| :------ | :------ |
|
||||||
| `name` | `string` | The name of the table. |
|
| `name` | `string` \| [`CreateTableOptions`](../interfaces/CreateTableOptions.md)\<`T`\> |
|
||||||
| `data` | `Record`<`string`, `unknown`\>[] | Non-empty Array of Records to be inserted into the Table |
|
| `data?` | `Record`\<`string`, `unknown`\>[] |
|
||||||
| `mode?` | [`WriteMode`](../enums/WriteMode.md) | The write mode to use when creating the table. |
|
| `optsOrEmbedding?` | [`WriteOptions`](../interfaces/WriteOptions.md) \| [`EmbeddingFunction`](../interfaces/EmbeddingFunction.md)\<`T`\> |
|
||||||
|
| `opt?` | [`WriteOptions`](../interfaces/WriteOptions.md) |
|
||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
|
|
||||||
`Promise`<[`Table`](../interfaces/Table.md)<`number`[]\>\>
|
`Promise`\<[`Table`](../interfaces/Table.md)\<`T`\>\>
|
||||||
|
|
||||||
#### Implementation of
|
#### Implementation of
|
||||||
|
|
||||||
@@ -112,120 +127,44 @@ Creates a new Table and initialize it with new data.
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:230](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L230)
|
[index.ts:542](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L542)
|
||||||
|
|
||||||
▸ **createTable**(`name`, `data`, `mode`): `Promise`<[`Table`](../interfaces/Table.md)<`number`[]\>\>
|
|
||||||
|
|
||||||
#### Parameters
|
|
||||||
|
|
||||||
| Name | Type |
|
|
||||||
| :------ | :------ |
|
|
||||||
| `name` | `string` |
|
|
||||||
| `data` | `Record`<`string`, `unknown`\>[] |
|
|
||||||
| `mode` | [`WriteMode`](../enums/WriteMode.md) |
|
|
||||||
|
|
||||||
#### Returns
|
|
||||||
|
|
||||||
`Promise`<[`Table`](../interfaces/Table.md)<`number`[]\>\>
|
|
||||||
|
|
||||||
#### Implementation of
|
|
||||||
|
|
||||||
Connection.createTable
|
|
||||||
|
|
||||||
#### Defined in
|
|
||||||
|
|
||||||
[index.ts:231](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L231)
|
|
||||||
|
|
||||||
▸ **createTable**<`T`\>(`name`, `data`, `mode`, `embeddings`): `Promise`<[`Table`](../interfaces/Table.md)<`T`\>\>
|
|
||||||
|
|
||||||
Creates a new Table and initialize it with new data.
|
|
||||||
|
|
||||||
#### Type parameters
|
|
||||||
|
|
||||||
| Name |
|
|
||||||
| :------ |
|
|
||||||
| `T` |
|
|
||||||
|
|
||||||
#### Parameters
|
|
||||||
|
|
||||||
| Name | Type | Description |
|
|
||||||
| :------ | :------ | :------ |
|
|
||||||
| `name` | `string` | The name of the table. |
|
|
||||||
| `data` | `Record`<`string`, `unknown`\>[] | Non-empty Array of Records to be inserted into the Table |
|
|
||||||
| `mode` | [`WriteMode`](../enums/WriteMode.md) | The write mode to use when creating the table. |
|
|
||||||
| `embeddings` | [`EmbeddingFunction`](../interfaces/EmbeddingFunction.md)<`T`\> | An embedding function to use on this Table |
|
|
||||||
|
|
||||||
#### Returns
|
|
||||||
|
|
||||||
`Promise`<[`Table`](../interfaces/Table.md)<`T`\>\>
|
|
||||||
|
|
||||||
#### Implementation of
|
|
||||||
|
|
||||||
Connection.createTable
|
|
||||||
|
|
||||||
#### Defined in
|
|
||||||
|
|
||||||
[index.ts:241](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L241)
|
|
||||||
|
|
||||||
▸ **createTable**<`T`\>(`name`, `data`, `mode`, `embeddings?`): `Promise`<[`Table`](../interfaces/Table.md)<`T`\>\>
|
|
||||||
|
|
||||||
#### Type parameters
|
|
||||||
|
|
||||||
| Name |
|
|
||||||
| :------ |
|
|
||||||
| `T` |
|
|
||||||
|
|
||||||
#### Parameters
|
|
||||||
|
|
||||||
| Name | Type |
|
|
||||||
| :------ | :------ |
|
|
||||||
| `name` | `string` |
|
|
||||||
| `data` | `Record`<`string`, `unknown`\>[] |
|
|
||||||
| `mode` | [`WriteMode`](../enums/WriteMode.md) |
|
|
||||||
| `embeddings?` | [`EmbeddingFunction`](../interfaces/EmbeddingFunction.md)<`T`\> |
|
|
||||||
|
|
||||||
#### Returns
|
|
||||||
|
|
||||||
`Promise`<[`Table`](../interfaces/Table.md)<`T`\>\>
|
|
||||||
|
|
||||||
#### Implementation of
|
|
||||||
|
|
||||||
Connection.createTable
|
|
||||||
|
|
||||||
#### Defined in
|
|
||||||
|
|
||||||
[index.ts:242](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L242)
|
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
### createTableArrow
|
### createTableImpl
|
||||||
|
|
||||||
▸ **createTableArrow**(`name`, `table`): `Promise`<[`Table`](../interfaces/Table.md)<`number`[]\>\>
|
▸ `Private` **createTableImpl**\<`T`\>(`«destructured»`): `Promise`\<[`Table`](../interfaces/Table.md)\<`T`\>\>
|
||||||
|
|
||||||
|
#### Type parameters
|
||||||
|
|
||||||
|
| Name |
|
||||||
|
| :------ |
|
||||||
|
| `T` |
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
| Name | Type |
|
| Name | Type |
|
||||||
| :------ | :------ |
|
| :------ | :------ |
|
||||||
| `name` | `string` |
|
| `«destructured»` | `Object` |
|
||||||
| `table` | `Table`<`any`\> |
|
| › `data?` | `Table`\<`any`\> \| `Record`\<`string`, `unknown`\>[] |
|
||||||
|
| › `embeddingFunction?` | [`EmbeddingFunction`](../interfaces/EmbeddingFunction.md)\<`T`\> |
|
||||||
|
| › `name` | `string` |
|
||||||
|
| › `schema?` | `Schema`\<`any`\> |
|
||||||
|
| › `writeOptions?` | [`WriteOptions`](../interfaces/WriteOptions.md) |
|
||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
|
|
||||||
`Promise`<[`Table`](../interfaces/Table.md)<`number`[]\>\>
|
`Promise`\<[`Table`](../interfaces/Table.md)\<`T`\>\>
|
||||||
|
|
||||||
#### Implementation of
|
|
||||||
|
|
||||||
[Connection](../interfaces/Connection.md).[createTableArrow](../interfaces/Connection.md#createtablearrow)
|
|
||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:266](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L266)
|
[index.ts:576](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L576)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
### dropTable
|
### dropTable
|
||||||
|
|
||||||
▸ **dropTable**(`name`): `Promise`<`void`\>
|
▸ **dropTable**(`name`): `Promise`\<`void`\>
|
||||||
|
|
||||||
Drop an existing table.
|
Drop an existing table.
|
||||||
|
|
||||||
@@ -237,7 +176,7 @@ Drop an existing table.
|
|||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
|
|
||||||
`Promise`<`void`\>
|
`Promise`\<`void`\>
|
||||||
|
|
||||||
#### Implementation of
|
#### Implementation of
|
||||||
|
|
||||||
@@ -245,13 +184,13 @@ Drop an existing table.
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:276](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L276)
|
[index.ts:630](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L630)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
### openTable
|
### openTable
|
||||||
|
|
||||||
▸ **openTable**(`name`): `Promise`<[`Table`](../interfaces/Table.md)<`number`[]\>\>
|
▸ **openTable**(`name`): `Promise`\<[`Table`](../interfaces/Table.md)\<`number`[]\>\>
|
||||||
|
|
||||||
Open a table in the database.
|
Open a table in the database.
|
||||||
|
|
||||||
@@ -263,7 +202,7 @@ Open a table in the database.
|
|||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
|
|
||||||
`Promise`<[`Table`](../interfaces/Table.md)<`number`[]\>\>
|
`Promise`\<[`Table`](../interfaces/Table.md)\<`number`[]\>\>
|
||||||
|
|
||||||
#### Implementation of
|
#### Implementation of
|
||||||
|
|
||||||
@@ -271,9 +210,9 @@ Open a table in the database.
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:205](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L205)
|
[index.ts:510](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L510)
|
||||||
|
|
||||||
▸ **openTable**<`T`\>(`name`, `embeddings`): `Promise`<[`Table`](../interfaces/Table.md)<`T`\>\>
|
▸ **openTable**\<`T`\>(`name`, `embeddings`): `Promise`\<[`Table`](../interfaces/Table.md)\<`T`\>\>
|
||||||
|
|
||||||
Open a table in the database.
|
Open a table in the database.
|
||||||
|
|
||||||
@@ -288,11 +227,11 @@ Open a table in the database.
|
|||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
| :------ | :------ | :------ |
|
| :------ | :------ | :------ |
|
||||||
| `name` | `string` | The name of the table. |
|
| `name` | `string` | The name of the table. |
|
||||||
| `embeddings` | [`EmbeddingFunction`](../interfaces/EmbeddingFunction.md)<`T`\> | An embedding function to use on this Table |
|
| `embeddings` | [`EmbeddingFunction`](../interfaces/EmbeddingFunction.md)\<`T`\> | An embedding function to use on this Table |
|
||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
|
|
||||||
`Promise`<[`Table`](../interfaces/Table.md)<`T`\>\>
|
`Promise`\<[`Table`](../interfaces/Table.md)\<`T`\>\>
|
||||||
|
|
||||||
#### Implementation of
|
#### Implementation of
|
||||||
|
|
||||||
@@ -300,9 +239,9 @@ Connection.openTable
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:212](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L212)
|
[index.ts:518](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L518)
|
||||||
|
|
||||||
▸ **openTable**<`T`\>(`name`, `embeddings?`): `Promise`<[`Table`](../interfaces/Table.md)<`T`\>\>
|
▸ **openTable**\<`T`\>(`name`, `embeddings?`): `Promise`\<[`Table`](../interfaces/Table.md)\<`T`\>\>
|
||||||
|
|
||||||
#### Type parameters
|
#### Type parameters
|
||||||
|
|
||||||
@@ -315,11 +254,11 @@ Connection.openTable
|
|||||||
| Name | Type |
|
| Name | Type |
|
||||||
| :------ | :------ |
|
| :------ | :------ |
|
||||||
| `name` | `string` |
|
| `name` | `string` |
|
||||||
| `embeddings?` | [`EmbeddingFunction`](../interfaces/EmbeddingFunction.md)<`T`\> |
|
| `embeddings?` | [`EmbeddingFunction`](../interfaces/EmbeddingFunction.md)\<`T`\> |
|
||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
|
|
||||||
`Promise`<[`Table`](../interfaces/Table.md)<`T`\>\>
|
`Promise`\<[`Table`](../interfaces/Table.md)\<`T`\>\>
|
||||||
|
|
||||||
#### Implementation of
|
#### Implementation of
|
||||||
|
|
||||||
@@ -327,19 +266,19 @@ Connection.openTable
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:213](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L213)
|
[index.ts:522](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L522)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
### tableNames
|
### tableNames
|
||||||
|
|
||||||
▸ **tableNames**(): `Promise`<`string`[]\>
|
▸ **tableNames**(): `Promise`\<`string`[]\>
|
||||||
|
|
||||||
Get the names of all tables in the database.
|
Get the names of all tables in the database.
|
||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
|
|
||||||
`Promise`<`string`[]\>
|
`Promise`\<`string`[]\>
|
||||||
|
|
||||||
#### Implementation of
|
#### Implementation of
|
||||||
|
|
||||||
@@ -347,4 +286,4 @@ Get the names of all tables in the database.
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:196](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L196)
|
[index.ts:501](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L501)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[vectordb](../README.md) / [Exports](../modules.md) / LocalTable
|
[vectordb](../README.md) / [Exports](../modules.md) / LocalTable
|
||||||
|
|
||||||
# Class: LocalTable<T\>
|
# Class: LocalTable\<T\>
|
||||||
|
|
||||||
A LanceDB Table is the collection of Records. Each Record has one or more vector fields.
|
A LanceDB Table is the collection of Records. Each Record has one or more vector fields.
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ A LanceDB Table is the collection of Records. Each Record has one or more vector
|
|||||||
|
|
||||||
## Implements
|
## Implements
|
||||||
|
|
||||||
- [`Table`](../interfaces/Table.md)<`T`\>
|
- [`Table`](../interfaces/Table.md)\<`T`\>
|
||||||
|
|
||||||
## Table of contents
|
## Table of contents
|
||||||
|
|
||||||
@@ -23,28 +23,40 @@ A LanceDB Table is the collection of Records. Each Record has one or more vector
|
|||||||
### Properties
|
### Properties
|
||||||
|
|
||||||
- [\_embeddings](LocalTable.md#_embeddings)
|
- [\_embeddings](LocalTable.md#_embeddings)
|
||||||
|
- [\_isElectron](LocalTable.md#_iselectron)
|
||||||
- [\_name](LocalTable.md#_name)
|
- [\_name](LocalTable.md#_name)
|
||||||
- [\_options](LocalTable.md#_options)
|
- [\_options](LocalTable.md#_options)
|
||||||
- [\_tbl](LocalTable.md#_tbl)
|
- [\_tbl](LocalTable.md#_tbl)
|
||||||
|
- [where](LocalTable.md#where)
|
||||||
|
|
||||||
### Accessors
|
### Accessors
|
||||||
|
|
||||||
- [name](LocalTable.md#name)
|
- [name](LocalTable.md#name)
|
||||||
|
- [schema](LocalTable.md#schema)
|
||||||
|
|
||||||
### Methods
|
### Methods
|
||||||
|
|
||||||
- [add](LocalTable.md#add)
|
- [add](LocalTable.md#add)
|
||||||
|
- [checkElectron](LocalTable.md#checkelectron)
|
||||||
|
- [cleanupOldVersions](LocalTable.md#cleanupoldversions)
|
||||||
|
- [compactFiles](LocalTable.md#compactfiles)
|
||||||
- [countRows](LocalTable.md#countrows)
|
- [countRows](LocalTable.md#countrows)
|
||||||
- [createIndex](LocalTable.md#createindex)
|
- [createIndex](LocalTable.md#createindex)
|
||||||
|
- [createScalarIndex](LocalTable.md#createscalarindex)
|
||||||
- [delete](LocalTable.md#delete)
|
- [delete](LocalTable.md#delete)
|
||||||
|
- [filter](LocalTable.md#filter)
|
||||||
|
- [getSchema](LocalTable.md#getschema)
|
||||||
|
- [indexStats](LocalTable.md#indexstats)
|
||||||
|
- [listIndices](LocalTable.md#listindices)
|
||||||
- [overwrite](LocalTable.md#overwrite)
|
- [overwrite](LocalTable.md#overwrite)
|
||||||
- [search](LocalTable.md#search)
|
- [search](LocalTable.md#search)
|
||||||
|
- [update](LocalTable.md#update)
|
||||||
|
|
||||||
## Constructors
|
## Constructors
|
||||||
|
|
||||||
### constructor
|
### constructor
|
||||||
|
|
||||||
• **new LocalTable**<`T`\>(`tbl`, `name`, `options`)
|
• **new LocalTable**\<`T`\>(`tbl`, `name`, `options`)
|
||||||
|
|
||||||
#### Type parameters
|
#### Type parameters
|
||||||
|
|
||||||
@@ -62,9 +74,9 @@ A LanceDB Table is the collection of Records. Each Record has one or more vector
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:287](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L287)
|
[index.ts:642](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L642)
|
||||||
|
|
||||||
• **new LocalTable**<`T`\>(`tbl`, `name`, `options`, `embeddings`)
|
• **new LocalTable**\<`T`\>(`tbl`, `name`, `options`, `embeddings`)
|
||||||
|
|
||||||
#### Type parameters
|
#### Type parameters
|
||||||
|
|
||||||
@@ -79,21 +91,31 @@ A LanceDB Table is the collection of Records. Each Record has one or more vector
|
|||||||
| `tbl` | `any` | |
|
| `tbl` | `any` | |
|
||||||
| `name` | `string` | |
|
| `name` | `string` | |
|
||||||
| `options` | [`ConnectionOptions`](../interfaces/ConnectionOptions.md) | |
|
| `options` | [`ConnectionOptions`](../interfaces/ConnectionOptions.md) | |
|
||||||
| `embeddings` | [`EmbeddingFunction`](../interfaces/EmbeddingFunction.md)<`T`\> | An embedding function to use when interacting with this table |
|
| `embeddings` | [`EmbeddingFunction`](../interfaces/EmbeddingFunction.md)\<`T`\> | An embedding function to use when interacting with this table |
|
||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:294](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L294)
|
[index.ts:649](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L649)
|
||||||
|
|
||||||
## Properties
|
## Properties
|
||||||
|
|
||||||
### \_embeddings
|
### \_embeddings
|
||||||
|
|
||||||
• `Private` `Optional` `Readonly` **\_embeddings**: [`EmbeddingFunction`](../interfaces/EmbeddingFunction.md)<`T`\>
|
• `Private` `Optional` `Readonly` **\_embeddings**: [`EmbeddingFunction`](../interfaces/EmbeddingFunction.md)\<`T`\>
|
||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:284](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L284)
|
[index.ts:639](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L639)
|
||||||
|
|
||||||
|
___
|
||||||
|
|
||||||
|
### \_isElectron
|
||||||
|
|
||||||
|
• `Private` `Readonly` **\_isElectron**: `boolean`
|
||||||
|
|
||||||
|
#### Defined in
|
||||||
|
|
||||||
|
[index.ts:638](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L638)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
@@ -103,27 +125,61 @@ ___
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:283](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L283)
|
[index.ts:637](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L637)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
### \_options
|
### \_options
|
||||||
|
|
||||||
• `Private` `Readonly` **\_options**: [`ConnectionOptions`](../interfaces/ConnectionOptions.md)
|
• `Private` `Readonly` **\_options**: () => [`ConnectionOptions`](../interfaces/ConnectionOptions.md)
|
||||||
|
|
||||||
|
#### Type declaration
|
||||||
|
|
||||||
|
▸ (): [`ConnectionOptions`](../interfaces/ConnectionOptions.md)
|
||||||
|
|
||||||
|
##### Returns
|
||||||
|
|
||||||
|
[`ConnectionOptions`](../interfaces/ConnectionOptions.md)
|
||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:285](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L285)
|
[index.ts:640](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L640)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
### \_tbl
|
### \_tbl
|
||||||
|
|
||||||
• `Private` `Readonly` **\_tbl**: `any`
|
• `Private` **\_tbl**: `any`
|
||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:282](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L282)
|
[index.ts:636](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L636)
|
||||||
|
|
||||||
|
___
|
||||||
|
|
||||||
|
### where
|
||||||
|
|
||||||
|
• **where**: (`value`: `string`) => [`Query`](Query.md)\<`T`\>
|
||||||
|
|
||||||
|
#### Type declaration
|
||||||
|
|
||||||
|
▸ (`value`): [`Query`](Query.md)\<`T`\>
|
||||||
|
|
||||||
|
Creates a filter query to find all rows matching the specified criteria
|
||||||
|
|
||||||
|
##### Parameters
|
||||||
|
|
||||||
|
| Name | Type | Description |
|
||||||
|
| :------ | :------ | :------ |
|
||||||
|
| `value` | `string` | The filter criteria (like SQL where clause syntax) |
|
||||||
|
|
||||||
|
##### Returns
|
||||||
|
|
||||||
|
[`Query`](Query.md)\<`T`\>
|
||||||
|
|
||||||
|
#### Defined in
|
||||||
|
|
||||||
|
[index.ts:688](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L688)
|
||||||
|
|
||||||
## Accessors
|
## Accessors
|
||||||
|
|
||||||
@@ -141,13 +197,31 @@ ___
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:302](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L302)
|
[index.ts:668](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L668)
|
||||||
|
|
||||||
|
___
|
||||||
|
|
||||||
|
### schema
|
||||||
|
|
||||||
|
• `get` **schema**(): `Promise`\<`Schema`\<`any`\>\>
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
|
||||||
|
`Promise`\<`Schema`\<`any`\>\>
|
||||||
|
|
||||||
|
#### Implementation of
|
||||||
|
|
||||||
|
[Table](../interfaces/Table.md).[schema](../interfaces/Table.md#schema)
|
||||||
|
|
||||||
|
#### Defined in
|
||||||
|
|
||||||
|
[index.ts:849](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L849)
|
||||||
|
|
||||||
## Methods
|
## Methods
|
||||||
|
|
||||||
### add
|
### add
|
||||||
|
|
||||||
▸ **add**(`data`): `Promise`<`number`\>
|
▸ **add**(`data`): `Promise`\<`number`\>
|
||||||
|
|
||||||
Insert records into this Table.
|
Insert records into this Table.
|
||||||
|
|
||||||
@@ -155,11 +229,11 @@ Insert records into this Table.
|
|||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
| :------ | :------ | :------ |
|
| :------ | :------ | :------ |
|
||||||
| `data` | `Record`<`string`, `unknown`\>[] | Records to be inserted into the Table |
|
| `data` | `Record`\<`string`, `unknown`\>[] | Records to be inserted into the Table |
|
||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
|
|
||||||
`Promise`<`number`\>
|
`Promise`\<`number`\>
|
||||||
|
|
||||||
The number of rows added to the table
|
The number of rows added to the table
|
||||||
|
|
||||||
@@ -169,19 +243,83 @@ The number of rows added to the table
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:320](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L320)
|
[index.ts:696](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L696)
|
||||||
|
|
||||||
|
___
|
||||||
|
|
||||||
|
### checkElectron
|
||||||
|
|
||||||
|
▸ `Private` **checkElectron**(): `boolean`
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
|
||||||
|
`boolean`
|
||||||
|
|
||||||
|
#### Defined in
|
||||||
|
|
||||||
|
[index.ts:861](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L861)
|
||||||
|
|
||||||
|
___
|
||||||
|
|
||||||
|
### cleanupOldVersions
|
||||||
|
|
||||||
|
▸ **cleanupOldVersions**(`olderThan?`, `deleteUnverified?`): `Promise`\<[`CleanupStats`](../interfaces/CleanupStats.md)\>
|
||||||
|
|
||||||
|
Clean up old versions of the table, freeing disk space.
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
|
||||||
|
| Name | Type | Description |
|
||||||
|
| :------ | :------ | :------ |
|
||||||
|
| `olderThan?` | `number` | The minimum age in minutes of the versions to delete. If not provided, defaults to two weeks. |
|
||||||
|
| `deleteUnverified?` | `boolean` | Because they may be part of an in-progress transaction, uncommitted files newer than 7 days old are not deleted by default. This means that failed transactions can leave around data that takes up disk space for up to 7 days. You can override this safety mechanism by setting this option to `true`, only if you promise there are no in progress writes while you run this operation. Failure to uphold this promise can lead to corrupted tables. |
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
|
||||||
|
`Promise`\<[`CleanupStats`](../interfaces/CleanupStats.md)\>
|
||||||
|
|
||||||
|
#### Defined in
|
||||||
|
|
||||||
|
[index.ts:808](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L808)
|
||||||
|
|
||||||
|
___
|
||||||
|
|
||||||
|
### compactFiles
|
||||||
|
|
||||||
|
▸ **compactFiles**(`options?`): `Promise`\<[`CompactionMetrics`](../interfaces/CompactionMetrics.md)\>
|
||||||
|
|
||||||
|
Run the compaction process on the table.
|
||||||
|
|
||||||
|
This can be run after making several small appends to optimize the table
|
||||||
|
for faster reads.
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
|
||||||
|
| Name | Type | Description |
|
||||||
|
| :------ | :------ | :------ |
|
||||||
|
| `options?` | [`CompactionOptions`](../interfaces/CompactionOptions.md) | Advanced options configuring compaction. In most cases, you can omit this arguments, as the default options are sensible for most tables. |
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
|
||||||
|
`Promise`\<[`CompactionMetrics`](../interfaces/CompactionMetrics.md)\>
|
||||||
|
|
||||||
|
Metrics about the compaction operation.
|
||||||
|
|
||||||
|
#### Defined in
|
||||||
|
|
||||||
|
[index.ts:831](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L831)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
### countRows
|
### countRows
|
||||||
|
|
||||||
▸ **countRows**(): `Promise`<`number`\>
|
▸ **countRows**(): `Promise`\<`number`\>
|
||||||
|
|
||||||
Returns the number of rows in this table.
|
Returns the number of rows in this table.
|
||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
|
|
||||||
`Promise`<`number`\>
|
`Promise`\<`number`\>
|
||||||
|
|
||||||
#### Implementation of
|
#### Implementation of
|
||||||
|
|
||||||
@@ -189,20 +327,16 @@ Returns the number of rows in this table.
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:362](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L362)
|
[index.ts:749](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L749)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
### createIndex
|
### createIndex
|
||||||
|
|
||||||
▸ **createIndex**(`indexParams`): `Promise`<`any`\>
|
▸ **createIndex**(`indexParams`): `Promise`\<`any`\>
|
||||||
|
|
||||||
Create an ANN index on this Table vector index.
|
Create an ANN index on this Table vector index.
|
||||||
|
|
||||||
**`See`**
|
|
||||||
|
|
||||||
VectorIndexParams.
|
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
@@ -211,7 +345,11 @@ VectorIndexParams.
|
|||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
|
|
||||||
`Promise`<`any`\>
|
`Promise`\<`any`\>
|
||||||
|
|
||||||
|
**`See`**
|
||||||
|
|
||||||
|
VectorIndexParams.
|
||||||
|
|
||||||
#### Implementation of
|
#### Implementation of
|
||||||
|
|
||||||
@@ -219,13 +357,48 @@ VectorIndexParams.
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:355](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L355)
|
[index.ts:734](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L734)
|
||||||
|
|
||||||
|
___
|
||||||
|
|
||||||
|
### createScalarIndex
|
||||||
|
|
||||||
|
▸ **createScalarIndex**(`column`, `replace`): `Promise`\<`void`\>
|
||||||
|
|
||||||
|
Create a scalar index on this Table for the given column
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
|
||||||
|
| Name | Type | Description |
|
||||||
|
| :------ | :------ | :------ |
|
||||||
|
| `column` | `string` | The column to index |
|
||||||
|
| `replace` | `boolean` | If false, fail if an index already exists on the column Scalar indices, like vector indices, can be used to speed up scans. A scalar index can speed up scans that contain filter expressions on the indexed column. For example, the following scan will be faster if the column `my_col` has a scalar index: ```ts const con = await lancedb.connect('./.lancedb'); const table = await con.openTable('images'); const results = await table.where('my_col = 7').execute(); ``` Scalar indices can also speed up scans containing a vector search and a prefilter: ```ts const con = await lancedb.connect('././lancedb'); const table = await con.openTable('images'); const results = await table.search([1.0, 2.0]).where('my_col != 7').prefilter(true); ``` Scalar indices can only speed up scans for basic filters using equality, comparison, range (e.g. `my_col BETWEEN 0 AND 100`), and set membership (e.g. `my_col IN (0, 1, 2)`) Scalar indices can be used if the filter contains multiple indexed columns and the filter criteria are AND'd or OR'd together (e.g. `my_col < 0 AND other_col> 100`) Scalar indices may be used if the filter contains non-indexed columns but, depending on the structure of the filter, they may not be usable. For example, if the column `not_indexed` does not have a scalar index then the filter `my_col = 0 OR not_indexed = 1` will not be able to use any scalar index on `my_col`. |
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
|
||||||
|
`Promise`\<`void`\>
|
||||||
|
|
||||||
|
**`Examples`**
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const con = await lancedb.connect('././lancedb')
|
||||||
|
const table = await con.openTable('images')
|
||||||
|
await table.createScalarIndex('my_col')
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Implementation of
|
||||||
|
|
||||||
|
[Table](../interfaces/Table.md).[createScalarIndex](../interfaces/Table.md#createscalarindex)
|
||||||
|
|
||||||
|
#### Defined in
|
||||||
|
|
||||||
|
[index.ts:742](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L742)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
### delete
|
### delete
|
||||||
|
|
||||||
▸ **delete**(`filter`): `Promise`<`void`\>
|
▸ **delete**(`filter`): `Promise`\<`void`\>
|
||||||
|
|
||||||
Delete rows from this table.
|
Delete rows from this table.
|
||||||
|
|
||||||
@@ -237,7 +410,7 @@ Delete rows from this table.
|
|||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
|
|
||||||
`Promise`<`void`\>
|
`Promise`\<`void`\>
|
||||||
|
|
||||||
#### Implementation of
|
#### Implementation of
|
||||||
|
|
||||||
@@ -245,13 +418,95 @@ Delete rows from this table.
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:371](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L371)
|
[index.ts:758](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L758)
|
||||||
|
|
||||||
|
___
|
||||||
|
|
||||||
|
### filter
|
||||||
|
|
||||||
|
▸ **filter**(`value`): [`Query`](Query.md)\<`T`\>
|
||||||
|
|
||||||
|
Creates a filter query to find all rows matching the specified criteria
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
|
||||||
|
| Name | Type | Description |
|
||||||
|
| :------ | :------ | :------ |
|
||||||
|
| `value` | `string` | The filter criteria (like SQL where clause syntax) |
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
|
||||||
|
[`Query`](Query.md)\<`T`\>
|
||||||
|
|
||||||
|
#### Defined in
|
||||||
|
|
||||||
|
[index.ts:684](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L684)
|
||||||
|
|
||||||
|
___
|
||||||
|
|
||||||
|
### getSchema
|
||||||
|
|
||||||
|
▸ `Private` **getSchema**(): `Promise`\<`Schema`\<`any`\>\>
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
|
||||||
|
`Promise`\<`Schema`\<`any`\>\>
|
||||||
|
|
||||||
|
#### Defined in
|
||||||
|
|
||||||
|
[index.ts:854](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L854)
|
||||||
|
|
||||||
|
___
|
||||||
|
|
||||||
|
### indexStats
|
||||||
|
|
||||||
|
▸ **indexStats**(`indexUuid`): `Promise`\<[`IndexStats`](../interfaces/IndexStats.md)\>
|
||||||
|
|
||||||
|
Get statistics about an index.
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
|
||||||
|
| Name | Type |
|
||||||
|
| :------ | :------ |
|
||||||
|
| `indexUuid` | `string` |
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
|
||||||
|
`Promise`\<[`IndexStats`](../interfaces/IndexStats.md)\>
|
||||||
|
|
||||||
|
#### Implementation of
|
||||||
|
|
||||||
|
[Table](../interfaces/Table.md).[indexStats](../interfaces/Table.md#indexstats)
|
||||||
|
|
||||||
|
#### Defined in
|
||||||
|
|
||||||
|
[index.ts:845](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L845)
|
||||||
|
|
||||||
|
___
|
||||||
|
|
||||||
|
### listIndices
|
||||||
|
|
||||||
|
▸ **listIndices**(): `Promise`\<[`VectorIndex`](../interfaces/VectorIndex.md)[]\>
|
||||||
|
|
||||||
|
List the indicies on this table.
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
|
||||||
|
`Promise`\<[`VectorIndex`](../interfaces/VectorIndex.md)[]\>
|
||||||
|
|
||||||
|
#### Implementation of
|
||||||
|
|
||||||
|
[Table](../interfaces/Table.md).[listIndices](../interfaces/Table.md#listindices)
|
||||||
|
|
||||||
|
#### Defined in
|
||||||
|
|
||||||
|
[index.ts:841](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L841)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
### overwrite
|
### overwrite
|
||||||
|
|
||||||
▸ **overwrite**(`data`): `Promise`<`number`\>
|
▸ **overwrite**(`data`): `Promise`\<`number`\>
|
||||||
|
|
||||||
Insert records into this Table, replacing its contents.
|
Insert records into this Table, replacing its contents.
|
||||||
|
|
||||||
@@ -259,11 +514,11 @@ Insert records into this Table, replacing its contents.
|
|||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
| :------ | :------ | :------ |
|
| :------ | :------ | :------ |
|
||||||
| `data` | `Record`<`string`, `unknown`\>[] | Records to be inserted into the Table |
|
| `data` | `Record`\<`string`, `unknown`\>[] | Records to be inserted into the Table |
|
||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
|
|
||||||
`Promise`<`number`\>
|
`Promise`\<`number`\>
|
||||||
|
|
||||||
The number of rows added to the table
|
The number of rows added to the table
|
||||||
|
|
||||||
@@ -273,13 +528,13 @@ The number of rows added to the table
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:338](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L338)
|
[index.ts:716](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L716)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
### search
|
### search
|
||||||
|
|
||||||
▸ **search**(`query`): [`Query`](Query.md)<`T`\>
|
▸ **search**(`query`): [`Query`](Query.md)\<`T`\>
|
||||||
|
|
||||||
Creates a search query to find the nearest neighbors of the given search term
|
Creates a search query to find the nearest neighbors of the given search term
|
||||||
|
|
||||||
@@ -291,7 +546,7 @@ Creates a search query to find the nearest neighbors of the given search term
|
|||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
|
|
||||||
[`Query`](Query.md)<`T`\>
|
[`Query`](Query.md)\<`T`\>
|
||||||
|
|
||||||
#### Implementation of
|
#### Implementation of
|
||||||
|
|
||||||
@@ -299,4 +554,30 @@ Creates a search query to find the nearest neighbors of the given search term
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:310](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L310)
|
[index.ts:676](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L676)
|
||||||
|
|
||||||
|
___
|
||||||
|
|
||||||
|
### update
|
||||||
|
|
||||||
|
▸ **update**(`args`): `Promise`\<`void`\>
|
||||||
|
|
||||||
|
Update rows in this table.
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
|
||||||
|
| Name | Type | Description |
|
||||||
|
| :------ | :------ | :------ |
|
||||||
|
| `args` | [`UpdateArgs`](../interfaces/UpdateArgs.md) \| [`UpdateSqlArgs`](../interfaces/UpdateSqlArgs.md) | see [UpdateArgs](../interfaces/UpdateArgs.md) and [UpdateSqlArgs](../interfaces/UpdateSqlArgs.md) for more details |
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
|
||||||
|
`Promise`\<`void`\>
|
||||||
|
|
||||||
|
#### Implementation of
|
||||||
|
|
||||||
|
[Table](../interfaces/Table.md).[update](../interfaces/Table.md#update)
|
||||||
|
|
||||||
|
#### Defined in
|
||||||
|
|
||||||
|
[index.ts:771](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/index.ts#L771)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ An embedding function that automatically creates vector representation for a giv
|
|||||||
|
|
||||||
## Implements
|
## Implements
|
||||||
|
|
||||||
- [`EmbeddingFunction`](../interfaces/EmbeddingFunction.md)<`string`\>
|
- [`EmbeddingFunction`](../interfaces/EmbeddingFunction.md)\<`string`\>
|
||||||
|
|
||||||
## Table of contents
|
## Table of contents
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ An embedding function that automatically creates vector representation for a giv
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[embedding/openai.ts:21](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/embedding/openai.ts#L21)
|
[embedding/openai.ts:21](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/embedding/openai.ts#L21)
|
||||||
|
|
||||||
## Properties
|
## Properties
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ An embedding function that automatically creates vector representation for a giv
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[embedding/openai.ts:19](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/embedding/openai.ts#L19)
|
[embedding/openai.ts:19](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/embedding/openai.ts#L19)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ ___
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[embedding/openai.ts:18](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/embedding/openai.ts#L18)
|
[embedding/openai.ts:18](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/embedding/openai.ts#L18)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
@@ -76,13 +76,13 @@ The name of the column that will be used as input for the Embedding Function.
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[embedding/openai.ts:50](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/embedding/openai.ts#L50)
|
[embedding/openai.ts:50](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/embedding/openai.ts#L50)
|
||||||
|
|
||||||
## Methods
|
## Methods
|
||||||
|
|
||||||
### embed
|
### embed
|
||||||
|
|
||||||
▸ **embed**(`data`): `Promise`<`number`[][]\>
|
▸ **embed**(`data`): `Promise`\<`number`[][]\>
|
||||||
|
|
||||||
Creates a vector representation for the given values.
|
Creates a vector representation for the given values.
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ Creates a vector representation for the given values.
|
|||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
|
|
||||||
`Promise`<`number`[][]\>
|
`Promise`\<`number`[][]\>
|
||||||
|
|
||||||
#### Implementation of
|
#### Implementation of
|
||||||
|
|
||||||
@@ -102,4 +102,4 @@ Creates a vector representation for the given values.
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[embedding/openai.ts:38](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/embedding/openai.ts#L38)
|
[embedding/openai.ts:38](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/embedding/openai.ts#L38)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[vectordb](../README.md) / [Exports](../modules.md) / Query
|
[vectordb](../README.md) / [Exports](../modules.md) / Query
|
||||||
|
|
||||||
# Class: Query<T\>
|
# Class: Query\<T\>
|
||||||
|
|
||||||
A builder for nearest neighbor queries for LanceDB.
|
A builder for nearest neighbor queries for LanceDB.
|
||||||
|
|
||||||
@@ -23,6 +23,7 @@ A builder for nearest neighbor queries for LanceDB.
|
|||||||
- [\_limit](Query.md#_limit)
|
- [\_limit](Query.md#_limit)
|
||||||
- [\_metricType](Query.md#_metrictype)
|
- [\_metricType](Query.md#_metrictype)
|
||||||
- [\_nprobes](Query.md#_nprobes)
|
- [\_nprobes](Query.md#_nprobes)
|
||||||
|
- [\_prefilter](Query.md#_prefilter)
|
||||||
- [\_query](Query.md#_query)
|
- [\_query](Query.md#_query)
|
||||||
- [\_queryVector](Query.md#_queryvector)
|
- [\_queryVector](Query.md#_queryvector)
|
||||||
- [\_refineFactor](Query.md#_refinefactor)
|
- [\_refineFactor](Query.md#_refinefactor)
|
||||||
@@ -34,9 +35,11 @@ A builder for nearest neighbor queries for LanceDB.
|
|||||||
|
|
||||||
- [execute](Query.md#execute)
|
- [execute](Query.md#execute)
|
||||||
- [filter](Query.md#filter)
|
- [filter](Query.md#filter)
|
||||||
|
- [isElectron](Query.md#iselectron)
|
||||||
- [limit](Query.md#limit)
|
- [limit](Query.md#limit)
|
||||||
- [metricType](Query.md#metrictype)
|
- [metricType](Query.md#metrictype)
|
||||||
- [nprobes](Query.md#nprobes)
|
- [nprobes](Query.md#nprobes)
|
||||||
|
- [prefilter](Query.md#prefilter)
|
||||||
- [refineFactor](Query.md#refinefactor)
|
- [refineFactor](Query.md#refinefactor)
|
||||||
- [select](Query.md#select)
|
- [select](Query.md#select)
|
||||||
|
|
||||||
@@ -44,7 +47,7 @@ A builder for nearest neighbor queries for LanceDB.
|
|||||||
|
|
||||||
### constructor
|
### constructor
|
||||||
|
|
||||||
• **new Query**<`T`\>(`tbl`, `query`, `embeddings?`)
|
• **new Query**\<`T`\>(`query?`, `tbl?`, `embeddings?`)
|
||||||
|
|
||||||
#### Type parameters
|
#### Type parameters
|
||||||
|
|
||||||
@@ -56,23 +59,23 @@ A builder for nearest neighbor queries for LanceDB.
|
|||||||
|
|
||||||
| Name | Type |
|
| Name | Type |
|
||||||
| :------ | :------ |
|
| :------ | :------ |
|
||||||
| `tbl` | `any` |
|
| `query?` | `T` |
|
||||||
| `query` | `T` |
|
| `tbl?` | `any` |
|
||||||
| `embeddings?` | [`EmbeddingFunction`](../interfaces/EmbeddingFunction.md)<`T`\> |
|
| `embeddings?` | [`EmbeddingFunction`](../interfaces/EmbeddingFunction.md)\<`T`\> |
|
||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:448](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L448)
|
[query.ts:38](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/query.ts#L38)
|
||||||
|
|
||||||
## Properties
|
## Properties
|
||||||
|
|
||||||
### \_embeddings
|
### \_embeddings
|
||||||
|
|
||||||
• `Private` `Optional` `Readonly` **\_embeddings**: [`EmbeddingFunction`](../interfaces/EmbeddingFunction.md)<`T`\>
|
• `Protected` `Optional` `Readonly` **\_embeddings**: [`EmbeddingFunction`](../interfaces/EmbeddingFunction.md)\<`T`\>
|
||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:446](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L446)
|
[query.ts:36](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/query.ts#L36)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
@@ -82,17 +85,17 @@ ___
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:444](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L444)
|
[query.ts:33](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/query.ts#L33)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
### \_limit
|
### \_limit
|
||||||
|
|
||||||
• `Private` **\_limit**: `number`
|
• `Private` `Optional` **\_limit**: `number`
|
||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:440](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L440)
|
[query.ts:29](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/query.ts#L29)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
@@ -102,7 +105,7 @@ ___
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:445](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L445)
|
[query.ts:34](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/query.ts#L34)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
@@ -112,17 +115,27 @@ ___
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:442](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L442)
|
[query.ts:31](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/query.ts#L31)
|
||||||
|
|
||||||
|
___
|
||||||
|
|
||||||
|
### \_prefilter
|
||||||
|
|
||||||
|
• `Private` **\_prefilter**: `boolean`
|
||||||
|
|
||||||
|
#### Defined in
|
||||||
|
|
||||||
|
[query.ts:35](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/query.ts#L35)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
### \_query
|
### \_query
|
||||||
|
|
||||||
• `Private` `Readonly` **\_query**: `T`
|
• `Private` `Optional` `Readonly` **\_query**: `T`
|
||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:438](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L438)
|
[query.ts:26](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/query.ts#L26)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
@@ -132,7 +145,7 @@ ___
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:439](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L439)
|
[query.ts:28](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/query.ts#L28)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
@@ -142,7 +155,7 @@ ___
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:441](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L441)
|
[query.ts:30](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/query.ts#L30)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
@@ -152,27 +165,27 @@ ___
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:443](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L443)
|
[query.ts:32](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/query.ts#L32)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
### \_tbl
|
### \_tbl
|
||||||
|
|
||||||
• `Private` `Readonly` **\_tbl**: `any`
|
• `Private` `Optional` `Readonly` **\_tbl**: `any`
|
||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:437](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L437)
|
[query.ts:27](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/query.ts#L27)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
### where
|
### where
|
||||||
|
|
||||||
• **where**: (`value`: `string`) => [`Query`](Query.md)<`T`\>
|
• **where**: (`value`: `string`) => [`Query`](Query.md)\<`T`\>
|
||||||
|
|
||||||
#### Type declaration
|
#### Type declaration
|
||||||
|
|
||||||
▸ (`value`): [`Query`](Query.md)<`T`\>
|
▸ (`value`): [`Query`](Query.md)\<`T`\>
|
||||||
|
|
||||||
A filter statement to be applied to this query.
|
A filter statement to be applied to this query.
|
||||||
|
|
||||||
@@ -184,17 +197,17 @@ A filter statement to be applied to this query.
|
|||||||
|
|
||||||
##### Returns
|
##### Returns
|
||||||
|
|
||||||
[`Query`](Query.md)<`T`\>
|
[`Query`](Query.md)\<`T`\>
|
||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:496](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L496)
|
[query.ts:87](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/query.ts#L87)
|
||||||
|
|
||||||
## Methods
|
## Methods
|
||||||
|
|
||||||
### execute
|
### execute
|
||||||
|
|
||||||
▸ **execute**<`T`\>(): `Promise`<`T`[]\>
|
▸ **execute**\<`T`\>(): `Promise`\<`T`[]\>
|
||||||
|
|
||||||
Execute the query and return the results as an Array of Objects
|
Execute the query and return the results as an Array of Objects
|
||||||
|
|
||||||
@@ -202,21 +215,21 @@ Execute the query and return the results as an Array of Objects
|
|||||||
|
|
||||||
| Name | Type |
|
| Name | Type |
|
||||||
| :------ | :------ |
|
| :------ | :------ |
|
||||||
| `T` | `Record`<`string`, `unknown`\> |
|
| `T` | `Record`\<`string`, `unknown`\> |
|
||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
|
|
||||||
`Promise`<`T`[]\>
|
`Promise`\<`T`[]\>
|
||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:519](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L519)
|
[query.ts:115](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/query.ts#L115)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
### filter
|
### filter
|
||||||
|
|
||||||
▸ **filter**(`value`): [`Query`](Query.md)<`T`\>
|
▸ **filter**(`value`): [`Query`](Query.md)\<`T`\>
|
||||||
|
|
||||||
A filter statement to be applied to this query.
|
A filter statement to be applied to this query.
|
||||||
|
|
||||||
@@ -228,17 +241,31 @@ A filter statement to be applied to this query.
|
|||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
|
|
||||||
[`Query`](Query.md)<`T`\>
|
[`Query`](Query.md)\<`T`\>
|
||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:491](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L491)
|
[query.ts:82](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/query.ts#L82)
|
||||||
|
|
||||||
|
___
|
||||||
|
|
||||||
|
### isElectron
|
||||||
|
|
||||||
|
▸ `Private` **isElectron**(): `boolean`
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
|
||||||
|
`boolean`
|
||||||
|
|
||||||
|
#### Defined in
|
||||||
|
|
||||||
|
[query.ts:142](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/query.ts#L142)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
### limit
|
### limit
|
||||||
|
|
||||||
▸ **limit**(`value`): [`Query`](Query.md)<`T`\>
|
▸ **limit**(`value`): [`Query`](Query.md)\<`T`\>
|
||||||
|
|
||||||
Sets the number of results that will be returned
|
Sets the number of results that will be returned
|
||||||
|
|
||||||
@@ -250,24 +277,20 @@ Sets the number of results that will be returned
|
|||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
|
|
||||||
[`Query`](Query.md)<`T`\>
|
[`Query`](Query.md)\<`T`\>
|
||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:464](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L464)
|
[query.ts:55](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/query.ts#L55)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
### metricType
|
### metricType
|
||||||
|
|
||||||
▸ **metricType**(`value`): [`Query`](Query.md)<`T`\>
|
▸ **metricType**(`value`): [`Query`](Query.md)\<`T`\>
|
||||||
|
|
||||||
The MetricType used for this Query.
|
The MetricType used for this Query.
|
||||||
|
|
||||||
**`See`**
|
|
||||||
|
|
||||||
MetricType for the different options
|
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
@@ -276,17 +299,21 @@ MetricType for the different options
|
|||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
|
|
||||||
[`Query`](Query.md)<`T`\>
|
[`Query`](Query.md)\<`T`\>
|
||||||
|
|
||||||
|
**`See`**
|
||||||
|
|
||||||
|
MetricType for the different options
|
||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:511](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L511)
|
[query.ts:102](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/query.ts#L102)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
### nprobes
|
### nprobes
|
||||||
|
|
||||||
▸ **nprobes**(`value`): [`Query`](Query.md)<`T`\>
|
▸ **nprobes**(`value`): [`Query`](Query.md)\<`T`\>
|
||||||
|
|
||||||
The number of probes used. A higher number makes search more accurate but also slower.
|
The number of probes used. A higher number makes search more accurate but also slower.
|
||||||
|
|
||||||
@@ -298,17 +325,37 @@ The number of probes used. A higher number makes search more accurate but also s
|
|||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
|
|
||||||
[`Query`](Query.md)<`T`\>
|
[`Query`](Query.md)\<`T`\>
|
||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:482](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L482)
|
[query.ts:73](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/query.ts#L73)
|
||||||
|
|
||||||
|
___
|
||||||
|
|
||||||
|
### prefilter
|
||||||
|
|
||||||
|
▸ **prefilter**(`value`): [`Query`](Query.md)\<`T`\>
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
|
||||||
|
| Name | Type |
|
||||||
|
| :------ | :------ |
|
||||||
|
| `value` | `boolean` |
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
|
||||||
|
[`Query`](Query.md)\<`T`\>
|
||||||
|
|
||||||
|
#### Defined in
|
||||||
|
|
||||||
|
[query.ts:107](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/query.ts#L107)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
### refineFactor
|
### refineFactor
|
||||||
|
|
||||||
▸ **refineFactor**(`value`): [`Query`](Query.md)<`T`\>
|
▸ **refineFactor**(`value`): [`Query`](Query.md)\<`T`\>
|
||||||
|
|
||||||
Refine the results by reading extra elements and re-ranking them in memory.
|
Refine the results by reading extra elements and re-ranking them in memory.
|
||||||
|
|
||||||
@@ -320,17 +367,17 @@ Refine the results by reading extra elements and re-ranking them in memory.
|
|||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
|
|
||||||
[`Query`](Query.md)<`T`\>
|
[`Query`](Query.md)\<`T`\>
|
||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:473](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L473)
|
[query.ts:64](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/query.ts#L64)
|
||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
### select
|
### select
|
||||||
|
|
||||||
▸ **select**(`value`): [`Query`](Query.md)<`T`\>
|
▸ **select**(`value`): [`Query`](Query.md)\<`T`\>
|
||||||
|
|
||||||
Return only the specified columns.
|
Return only the specified columns.
|
||||||
|
|
||||||
@@ -342,8 +389,8 @@ Return only the specified columns.
|
|||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
|
|
||||||
[`Query`](Query.md)<`T`\>
|
[`Query`](Query.md)\<`T`\>
|
||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[index.ts:502](https://github.com/lancedb/lancedb/blob/b1eeb90/node/src/index.ts#L502)
|
[query.ts:93](https://github.com/lancedb/lancedb/blob/c89d5e6/node/src/query.ts#L93)
|
||||||
|
|||||||