Elffuss BraidHub

kikocis/lancedb public

main · 1.3 KiBRawPermalink
1// Copyright 2024 Lance Developers.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15import * as lancedb from "@lancedb/lancedb";
16
17const db = await lancedb.connect("data/sample-lancedb");
18
19const words = [
20 "apple",
21 "banana",
22 "cherry",
23 "date",
24 "elderberry",
25 "fig",
26 "grape",
27];
28
29const data = Array.from({ length: 10_000 }, (_, i) => ({
30 vector: Array(1536).fill(i),
31 id: i,
32 item: `item ${i}`,
33 strId: `${i}`,
34 doc: words[i % words.length],
35}));
36
37const tbl = await db.createTable("myVectors", data, { mode: "overwrite" });
38
39await tbl.createIndex("doc", {
40 config: lancedb.Index.fts(),
41});
42
43// --8<-- [start:full_text_search]
44let result = await tbl
45 .search("apple")
46 .select(["id", "doc"])
47 .limit(10)
48 .toArray();
49console.log(result);
50// --8<-- [end:full_text_search]
51
52console.log("SQL search: done");