| 1 | import * as lancedb from "@lancedb/lancedb"; |
| 2 | |
| 3 | import { LanceSchema, getRegistry } from "@lancedb/lancedb/embedding"; |
| 4 | import { Utf8 } from "apache-arrow"; |
| 5 | |
| 6 | const db = await lancedb.connect("/tmp/db"); |
| 7 | const func = await getRegistry().get("huggingface").create(); |
| 8 | |
| 9 | const facts = [ |
| 10 | "Albert Einstein was a theoretical physicist.", |
| 11 | "The capital of France is Paris.", |
| 12 | "The Great Wall of China is one of the Seven Wonders of the World.", |
| 13 | "Python is a popular programming language.", |
| 14 | "Mount Everest is the highest mountain in the world.", |
| 15 | "Leonardo da Vinci painted the Mona Lisa.", |
| 16 | "Shakespeare wrote Hamlet.", |
| 17 | "The human body has 206 bones.", |
| 18 | "The speed of light is approximately 299,792 kilometers per second.", |
| 19 | "Water boils at 100 degrees Celsius.", |
| 20 | "The Earth orbits the Sun.", |
| 21 | "The Pyramids of Giza are located in Egypt.", |
| 22 | "Coffee is one of the most popular beverages in the world.", |
| 23 | "Tokyo is the capital city of Japan.", |
| 24 | "Photosynthesis is the process by which plants make their food.", |
| 25 | "The Pacific Ocean is the largest ocean on Earth.", |
| 26 | "Mozart was a prolific composer of classical music.", |
| 27 | "The Internet is a global network of computers.", |
| 28 | "Basketball is a sport played with a ball and a hoop.", |
| 29 | "The first computer virus was created in 1983.", |
| 30 | "Artificial neural networks are inspired by the human brain.", |
| 31 | "Deep learning is a subset of machine learning.", |
| 32 | "IBM's Watson won Jeopardy! in 2011.", |
| 33 | "The first computer programmer was Ada Lovelace.", |
| 34 | "The first chatbot was ELIZA, created in the 1960s.", |
| 35 | ].map((text) => ({ text })); |
| 36 | |
| 37 | const factsSchema = LanceSchema({ |
| 38 | text: func.sourceField(new Utf8()), |
| 39 | vector: func.vectorField(), |
| 40 | }); |
| 41 | |
| 42 | const tbl = await db.createTable("facts", facts, { |
| 43 | mode: "overwrite", |
| 44 | schema: factsSchema, |
| 45 | }); |
| 46 | |
| 47 | const query = "How many bones are in the human body?"; |
| 48 | const actual = await tbl.search(query).limit(1).toArray(); |
| 49 | |
| 50 | console.log("Answer: ", actual[0]["text"]); |