| 1 | # LanceDB |
| 2 | |
| 3 | A Python library for [LanceDB](https://github.com/lancedb/lancedb). |
| 4 | |
| 5 | ## Installation |
| 6 | |
| 7 | ```bash |
| 8 | pip install lancedb |
| 9 | ``` |
| 10 | |
| 11 | ## Usage |
| 12 | |
| 13 | ### Basic Example |
| 14 | |
| 15 | ```python |
| 16 | import lancedb |
| 17 | db = lancedb.connect('<PATH_TO_LANCEDB_DATASET>') |
| 18 | table = db.open_table('my_table') |
| 19 | results = table.search([0.1, 0.3]).limit(20).to_list() |
| 20 | print(results) |
| 21 | ``` |
| 22 | |
| 23 | ## Development |
| 24 | |
| 25 | LanceDb is based on the rust crate `lancedb` and is built with maturin. In order to build with maturin |
| 26 | you will either need a conda environment or a virtual environment (venv). |
| 27 | |
| 28 | ```bash |
| 29 | python -m venv venv |
| 30 | . ./venv/bin/activate |
| 31 | ``` |
| 32 | |
| 33 | Install the necessary packages: |
| 34 | |
| 35 | ```bash |
| 36 | python -m pip install .[tests,dev] |
| 37 | ``` |
| 38 | |
| 39 | To build the python package you can use maturin: |
| 40 | |
| 41 | ```bash |
| 42 | # This will build the rust bindings and place them in the appropriate place |
| 43 | # in your venv or conda environment |
| 44 | maturin develop |
| 45 | ``` |
| 46 | |
| 47 | To run the unit tests: |
| 48 | |
| 49 | ```bash |
| 50 | pytest |
| 51 | ``` |
| 52 | |
| 53 | To run the doc tests: |
| 54 | |
| 55 | ```bash |
| 56 | pytest --doctest-modules python/lancedb |
| 57 | ``` |
| 58 | |
| 59 | To run linter and automatically fix all errors: |
| 60 | |
| 61 | ```bash |
| 62 | ruff format python |
| 63 | ruff --fix python |
| 64 | ``` |
| 65 | |
| 66 | If any packages are missing, install them with: |
| 67 | |
| 68 | ```bash |
| 69 | pip install <PACKAGE_NAME> |
| 70 | ``` |
| 71 | |
| 72 | ___ |
| 73 | For **Windows** users, there may be errors when installing packages, so these commands may be helpful: |
| 74 | |
| 75 | Activate the virtual environment: |
| 76 | |
| 77 | ```bash |
| 78 | . .\venv\Scripts\activate |
| 79 | ``` |
| 80 | |
| 81 | You may need to run the installs separately: |
| 82 | |
| 83 | ```bash |
| 84 | pip install -e .[tests] |
| 85 | pip install -e .[dev] |
| 86 | ``` |
| 87 | |
| 88 | `tantivy` requires `rust` to be installed, so install it with `conda`, as it doesn't support windows installation: |
| 89 | |
| 90 | ```bash |
| 91 | pip install wheel |
| 92 | pip install cargo |
| 93 | conda install rust |
| 94 | pip install tantivy |
| 95 | ``` |