LynseDB 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. lynsedb-0.0.1/LICENSE +201 -0
  2. lynsedb-0.0.1/LynseDB.egg-info/PKG-INFO +490 -0
  3. lynsedb-0.0.1/LynseDB.egg-info/SOURCES.txt +61 -0
  4. lynsedb-0.0.1/LynseDB.egg-info/dependency_links.txt +1 -0
  5. lynsedb-0.0.1/LynseDB.egg-info/entry_points.txt +2 -0
  6. lynsedb-0.0.1/LynseDB.egg-info/not-zip-safe +1 -0
  7. lynsedb-0.0.1/LynseDB.egg-info/requires.txt +17 -0
  8. lynsedb-0.0.1/LynseDB.egg-info/top_level.txt +2 -0
  9. lynsedb-0.0.1/PKG-INFO +490 -0
  10. lynsedb-0.0.1/README.md +451 -0
  11. lynsedb-0.0.1/lynse/__init__.py +219 -0
  12. lynsedb-0.0.1/lynse/api/__init__.py +12 -0
  13. lynsedb-0.0.1/lynse/api/http_api/__init__.py +0 -0
  14. lynsedb-0.0.1/lynse/api/http_api/client_api.py +1196 -0
  15. lynsedb-0.0.1/lynse/api/http_api/http_api.py +1145 -0
  16. lynsedb-0.0.1/lynse/api/native_api/__init__.py +0 -0
  17. lynsedb-0.0.1/lynse/api/native_api/database_manager.py +60 -0
  18. lynsedb-0.0.1/lynse/api/native_api/high_level.py +361 -0
  19. lynsedb-0.0.1/lynse/api/native_api/low_level.py +450 -0
  20. lynsedb-0.0.1/lynse/computational_layer/__init__.py +0 -0
  21. lynsedb-0.0.1/lynse/computational_layer/engines.py +114 -0
  22. lynsedb-0.0.1/lynse/configs/__init__.py +0 -0
  23. lynsedb-0.0.1/lynse/configs/config.py +80 -0
  24. lynsedb-0.0.1/lynse/configs/parameters_validator.py +94 -0
  25. lynsedb-0.0.1/lynse/core_components/__init__.py +0 -0
  26. lynsedb-0.0.1/lynse/core_components/id_checker.py +44 -0
  27. lynsedb-0.0.1/lynse/core_components/ivf_index.py +221 -0
  28. lynsedb-0.0.1/lynse/core_components/kmeans.py +67 -0
  29. lynsedb-0.0.1/lynse/core_components/kv_cache/__init__.py +204 -0
  30. lynsedb-0.0.1/lynse/core_components/kv_cache/filter.py +305 -0
  31. lynsedb-0.0.1/lynse/core_components/kv_cache/index.py +286 -0
  32. lynsedb-0.0.1/lynse/core_components/kv_cache/kv_query.py +283 -0
  33. lynsedb-0.0.1/lynse/core_components/kv_cache/kv_storage.py +215 -0
  34. lynsedb-0.0.1/lynse/core_components/limited_array.py +101 -0
  35. lynsedb-0.0.1/lynse/core_components/limited_dict.py +90 -0
  36. lynsedb-0.0.1/lynse/core_components/limited_sort.py +66 -0
  37. lynsedb-0.0.1/lynse/core_components/locks.py +21 -0
  38. lynsedb-0.0.1/lynse/core_components/safe_dict.py +29 -0
  39. lynsedb-0.0.1/lynse/core_components/scaler.py +104 -0
  40. lynsedb-0.0.1/lynse/core_components/thread_safe_list.py +51 -0
  41. lynsedb-0.0.1/lynse/execution_layer/__init__.py +0 -0
  42. lynsedb-0.0.1/lynse/execution_layer/cluster_worker.py +166 -0
  43. lynsedb-0.0.1/lynse/execution_layer/matrix_serializer.py +396 -0
  44. lynsedb-0.0.1/lynse/execution_layer/search.py +202 -0
  45. lynsedb-0.0.1/lynse/execution_layer/session.py +47 -0
  46. lynsedb-0.0.1/lynse/storage_layer/__init__.py +0 -0
  47. lynsedb-0.0.1/lynse/storage_layer/storage.py +384 -0
  48. lynsedb-0.0.1/lynse/storage_layer/wal.py +186 -0
  49. lynsedb-0.0.1/lynse/utils/__init__.py +10 -0
  50. lynsedb-0.0.1/lynse/utils/poster.py +47 -0
  51. lynsedb-0.0.1/lynse/utils/utils.py +96 -0
  52. lynsedb-0.0.1/setup.cfg +4 -0
  53. lynsedb-0.0.1/setup.py +47 -0
  54. lynsedb-0.0.1/test/__init__.py +5 -0
  55. lynsedb-0.0.1/test/docker_tests/__init__.py +0 -0
  56. lynsedb-0.0.1/test/docker_tests/test_client_api.py +96 -0
  57. lynsedb-0.0.1/test/docker_tests/test_docker_api.py +87 -0
  58. lynsedb-0.0.1/test/standard_tests/__init__.py +0 -0
  59. lynsedb-0.0.1/test/standard_tests/test_hl_initial.py +50 -0
  60. lynsedb-0.0.1/test/standard_tests/test_http_api.py +283 -0
  61. lynsedb-0.0.1/test/standard_tests/test_ll_initial.py +63 -0
  62. lynsedb-0.0.1/test/standard_tests/test_ll_save_and_query.py +630 -0
  63. lynsedb-0.0.1/test/standard_tests/test_multi_threads.py +41 -0
lynsedb-0.0.1/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,490 @@
1
+ Metadata-Version: 2.1
2
+ Name: LynseDB
3
+ Version: 0.0.1
4
+ Summary: A pure Python-implemented, lightweight, server-optional, multi-end compatible, vector database deployable locally or remotely.
5
+ Home-page: https://github.com/BirchKwok/MinVectorDB
6
+ Author: Birch Kwok
7
+ Author-email: birchkwok@gmail.com
8
+ Keywords: vector database
9
+ Classifier: Intended Audience :: Science/Research
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Topic :: Software Development
12
+ Classifier: Topic :: Scientific/Engineering
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Requires-Python: >=3.9
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: numpy>=1.17.0
23
+ Requires-Dist: spinesUtils>=0.4.1
24
+ Requires-Dist: msgpack>=1.0.2
25
+ Requires-Dist: scikit-learn>=1.0.0
26
+ Requires-Dist: cloudpickle>=2.0.0
27
+ Requires-Dist: numexpr>=2.7.3
28
+ Requires-Dist: pyroaring>=0.4.5
29
+ Requires-Dist: jax>=0.4.25
30
+ Requires-Dist: jaxlib>=0.4.25
31
+ Requires-Dist: flask>=2.0.1
32
+ Requires-Dist: waitress>=2.0.0
33
+ Requires-Dist: pytest>=7.4.4
34
+ Requires-Dist: tqdm>=4.62.3
35
+ Requires-Dist: setuptools>=68.0.0
36
+ Requires-Dist: httpx[http2]>=0.19.0
37
+ Requires-Dist: pandas>=1.3.3
38
+ Requires-Dist: h5py>=3.4.0
39
+
40
+ <div align="center">
41
+ <picture>
42
+ <source media="(prefers-color-scheme: light)" srcset="https://github.com/BirchKwok/LynseDB/blob/main/pic/logo.png">
43
+ <source media="(prefers-color-scheme: dark)" srcset="https://github.com/BirchKwok/LynseDB/blob/main/pic/logo.png">
44
+ <img alt="LynseDB logo" src="https://github.com/BirchKwok/LynseDB/blob/main/pic/logo.png" height="100">
45
+ </picture>
46
+ </div>
47
+ <br>
48
+
49
+ <p align="center">
50
+ <a href="https://discord.com/invite/rcYK5nYF"><img src="https://img.shields.io/badge/Discord-Online-brightgreen" alt="Discord"></a>
51
+ <a href="https://badge.fury.io/py/LynseDB"><img src="https://badge.fury.io/py/LynseDB.svg" alt="PyPI version"></a>
52
+ <a href="https://pypi.org/project/LynseDB/"><img src="https://img.shields.io/pypi/pyversions/LynseDB" alt="PyPI - Python Version"></a>
53
+ <a href="https://pypi.org/project/LynseDB/"><img src="https://img.shields.io/pypi/l/LynseDB" alt="PyPI - License"></a>
54
+ <a href="https://github.com/BirchKwok/LynseDB/actions/workflows/python-tests.yml"><img src="https://github.com/BirchKwok/LynseDB/actions/workflows/python-tests.yml/badge.svg" alt="Python testing"></a>
55
+ <a href="https://github.com/BirchKwok/LynseDB/actions/workflows/docker-tests.yml"><img src="https://github.com/BirchKwok/LynseDB/actions/workflows/docker-tests.yml/badge.svg" alt="Docker build"></a>
56
+ </p>
57
+
58
+
59
+ ⚡ **Server-optional, simple parameters, simple API.**
60
+
61
+ ⚡ **Fast, memory-efficient, easily scales to millions of vectors.**
62
+
63
+ ⚡ **Friendly caching technology stores recently queried vectors for accelerated access.**
64
+
65
+ ⚡ **Based on a generic Python software stack, platform-independent, highly versatile.**
66
+
67
+ *LynseDB* is a vector database implemented purely in Python, designed to be lightweight, server-optional, and easy to deploy locally or remotely. It offers straightforward and clear Python APIs, aiming to lower the entry barrier for using vector databases.
68
+
69
+ LynseDB focuses on achieving 100% recall, prioritizing recall accuracy over high-speed search performance. This approach ensures that users can reliably retrieve all relevant vector data, making LynseDB particularly suitable for applications that require responses within hundreds of milliseconds.
70
+
71
+ - [x] **Now supports HTTP API and Python local code API and Docker deployment.**
72
+ - [X] **Now supports transaction management; if a commit fails, it will automatically roll back.**
73
+
74
+ <br>
75
+
76
+ :warning: **WARNING**
77
+
78
+ **Not yet backward compatible**
79
+
80
+ LynseDB is actively being updated, and API backward compatibility is not guaranteed. You should use version numbers as a strong constraint during deployment to avoid unnecessary feature conflicts and errors.
81
+
82
+ **Data size constraints**
83
+
84
+ Although our goal is to enable brute force search or inverted indexing on billion-scale vectors, we currently still recommend using it on a scale of millions of vectors or less for the best experience.
85
+
86
+ **python's native api is not process-safe**
87
+
88
+ The Python native API is recommended for use in single-process environments, whether single-threaded or multi-threaded; for ensuring process safety in multi-process environments, please use the HTTP API.
89
+
90
+
91
+ ## Prerequisite
92
+
93
+ - [x] python version >= 3.9
94
+ - [x] Owns one of the operating systems: Windows, macOS, or Ubuntu (or other Linux distributions). The recommendation is for the latest version of the system, but non-latest versions should also be installable, although they have not been tested.
95
+ - [x] Memory >= 4GB, Free Disk >= 4GB.
96
+
97
+ ## Install Client API package (Mandatory)
98
+
99
+ ```shell
100
+ pip install LynseDB
101
+ ```
102
+
103
+ ## If you wish to use Docker (Optional)
104
+
105
+ **You must first [install Docker](https://docs.docker.com/engine/install/) on the host machine.**
106
+
107
+ ```shell
108
+ docker pull birchkwok/LynseDB:latest
109
+ ```
110
+
111
+ ## Qucik Start
112
+
113
+ ```python
114
+ import lynse
115
+
116
+ print("LynseDB version is: ", lynse.__version__)
117
+ ```
118
+
119
+ LynseDB version is: 0.0.1
120
+
121
+
122
+ ## Initialize Database
123
+
124
+ LynseDB now supports HTTP API and Python native code API.
125
+
126
+
127
+ The HTTP API mode requires starting an HTTP server beforehand. You have two options:
128
+ - start directly.
129
+
130
+ For direct startup, the default port is 7637. You can run the following command in the terminal to start the service:
131
+ ```shell
132
+ lynse run --host localhost --port 7637
133
+ ```
134
+
135
+ - within Docker
136
+
137
+ In Docker, You can run the following command in the terminal to start the service:
138
+ ```shell
139
+ docker run -p 7637:7637 birchkwok/LynseDB:latest
140
+ ```
141
+ - Remote deploy
142
+
143
+ If you want to deploy remotely, you can bind the image to port 80 of the remote host, or allow the host to open access to port 7637.
144
+ such as:
145
+ ```shell
146
+ docker run -p 80:7637 birchkwok/LynseDB:latest
147
+ ```
148
+
149
+ - test if api available
150
+
151
+ You can directly request in the browser http://localhost:7637
152
+
153
+ For port 80, you can use this url: http://localhost
154
+
155
+ If the image is bound to port 80 of the host in remote deployment, you can directly access it http://your_host_ip
156
+
157
+ ```python
158
+ from lynse import LynseDB
159
+
160
+ # Use the HTTP API mode, it is suitable for use in production environments.
161
+ my_db = LynseDB("http://localhost:7637")
162
+ # Or use the Python native code API by specifying the database root directory.
163
+ # my_db = LynseDB('my_vec_db') # Judgment condition, root_path does not start with http or https
164
+ # The Python native code API is recommended only for CI/CD testing or single-user local use.
165
+ ```
166
+
167
+ ### create a collection
168
+
169
+ **`WARNING`**
170
+
171
+ When using the `require_collection` method to request a collection, if the `drop_if_exists` parameter is set to True, it will delete all content of the collection if it already exists.
172
+
173
+ A safer method is to use the `get_collection` method. It is recommended to use the `require_collection` method only when you need to reinitialize a collection or create a new one.
174
+
175
+
176
+ ```python
177
+ collection = my_db.require_collection("test_collection", dim=4, drop_if_exists=True, scaler_bits=8, description="demo collection")
178
+ ```
179
+
180
+ #### show database collections
181
+
182
+
183
+ ```python
184
+ my_db.show_collections_details()
185
+ ```
186
+
187
+
188
+
189
+
190
+ <div>
191
+ <table border="1" class="dataframe">
192
+ <thead>
193
+ <tr style="text-align: right;">
194
+ <th></th>
195
+ <th>chunk_size</th>
196
+ <th>description</th>
197
+ <th>dim</th>
198
+ <th>distance</th>
199
+ <th>dtypes</th>
200
+ <th>index_mode</th>
201
+ <th>initialize_as_collection</th>
202
+ <th>n_clusters</th>
203
+ <th>n_threads</th>
204
+ <th>scaler_bits</th>
205
+ <th>use_cache</th>
206
+ <th>warm_up</th>
207
+ </tr>
208
+ <tr>
209
+ <th>collections</th>
210
+ <th></th>
211
+ <th></th>
212
+ <th></th>
213
+ <th></th>
214
+ <th></th>
215
+ <th></th>
216
+ <th></th>
217
+ <th></th>
218
+ <th></th>
219
+ <th></th>
220
+ <th></th>
221
+ <th></th>
222
+ </tr>
223
+ </thead>
224
+ <tbody>
225
+ <tr>
226
+ <th>test_collection</th>
227
+ <td>100000</td>
228
+ <td>demo collection</td>
229
+ <td>4</td>
230
+ <td>cosine</td>
231
+ <td>float32</td>
232
+ <td>IVF-FLAT</td>
233
+ <td>True</td>
234
+ <td>16</td>
235
+ <td>10</td>
236
+ <td>8</td>
237
+ <td>True</td>
238
+ <td>False</td>
239
+ </tr>
240
+ </tbody>
241
+ </table>
242
+ </div>
243
+
244
+
245
+
246
+ #### update description
247
+
248
+
249
+ ```python
250
+ collection.update_description("test2")
251
+ my_db.show_collections_details()
252
+ ```
253
+
254
+
255
+
256
+
257
+ <div>
258
+ <table border="1" class="dataframe">
259
+ <thead>
260
+ <tr style="text-align: right;">
261
+ <th></th>
262
+ <th>chunk_size</th>
263
+ <th>description</th>
264
+ <th>dim</th>
265
+ <th>distance</th>
266
+ <th>dtypes</th>
267
+ <th>index_mode</th>
268
+ <th>initialize_as_collection</th>
269
+ <th>n_clusters</th>
270
+ <th>n_threads</th>
271
+ <th>scaler_bits</th>
272
+ <th>use_cache</th>
273
+ <th>warm_up</th>
274
+ </tr>
275
+ <tr>
276
+ <th>collections</th>
277
+ <th></th>
278
+ <th></th>
279
+ <th></th>
280
+ <th></th>
281
+ <th></th>
282
+ <th></th>
283
+ <th></th>
284
+ <th></th>
285
+ <th></th>
286
+ <th></th>
287
+ <th></th>
288
+ <th></th>
289
+ </tr>
290
+ </thead>
291
+ <tbody>
292
+ <tr>
293
+ <th>test_collection</th>
294
+ <td>100000</td>
295
+ <td>test2</td>
296
+ <td>4</td>
297
+ <td>cosine</td>
298
+ <td>float32</td>
299
+ <td>IVF-FLAT</td>
300
+ <td>True</td>
301
+ <td>16</td>
302
+ <td>10</td>
303
+ <td>8</td>
304
+ <td>True</td>
305
+ <td>False</td>
306
+ </tr>
307
+ </tbody>
308
+ </table>
309
+ </div>
310
+
311
+
312
+
313
+ ### Add vectors
314
+
315
+ When inserting vectors, collection requires manually running the `commit` function or inserting within the `insert_session` function context manager, which will run the `commit` function in the background.
316
+
317
+
318
+ ```python
319
+ with collection.insert_session():
320
+ id = collection.add_item(vector=[0.01, 0.34, 0.74, 0.31], id=1, field={'field': 'test_1', 'order': 0}) # id = 0
321
+ id = collection.add_item(vector=[0.36, 0.43, 0.56, 0.12], id=2, field={'field': 'test_1', 'order': 1}) # id = 1
322
+ id = collection.add_item(vector=[0.03, 0.04, 0.10, 0.51], id=3, field={'field': 'test_2', 'order': 2}) # id = 2
323
+ id = collection.add_item(vector=[0.11, 0.44, 0.23, 0.24], id=4, field={'field': 'test_2', 'order': 3}) # id = 3
324
+ id = collection.add_item(vector=[0.91, 0.43, 0.44, 0.67], id=5, field={'field': 'test_2', 'order': 4}) # id = 4
325
+ id = collection.add_item(vector=[0.92, 0.12, 0.56, 0.19], id=6, field={'field': 'test_3', 'order': 5}) # id = 5
326
+ id = collection.add_item(vector=[0.18, 0.34, 0.56, 0.71], id=7, field={'field': 'test_1', 'order': 6}) # id = 6
327
+ id = collection.add_item(vector=[0.01, 0.33, 0.14, 0.31], id=8, field={'field': 'test_2', 'order': 7}) # id = 7
328
+ id = collection.add_item(vector=[0.71, 0.75, 0.91, 0.82], id=9, field={'field': 'test_3', 'order': 8}) # id = 8
329
+ id = collection.add_item(vector=[0.75, 0.44, 0.38, 0.75], id=10, field={'field': 'test_1', 'order': 9}) # id = 9
330
+
331
+ # If you do not use the insert_session function, you need to manually call the commit function to submit the data
332
+ # collection.commit()
333
+ ```
334
+
335
+
336
+ ```python
337
+ # or use the bulk_add_items function
338
+ # with collection.insert_session():
339
+ # ids = collection.bulk_add_items([([0.01, 0.34, 0.74, 0.31], 0, {'field': 'test_1', 'order': 0}),
340
+ # ([0.36, 0.43, 0.56, 0.12], 1, {'field': 'test_1', 'order': 1}),
341
+ # ([0.03, 0.04, 0.10, 0.51], 2, {'field': 'test_2', 'order': 2}),
342
+ # ([0.11, 0.44, 0.23, 0.24], 3, {'field': 'test_2', 'order': 3}),
343
+ # ([0.91, 0.43, 0.44, 0.67], 4, {'field': 'test_2', 'order': 4}),
344
+ # ([0.92, 0.12, 0.56, 0.19], 5, {'field': 'test_3', 'order': 5}),
345
+ # ([0.18, 0.34, 0.56, 0.71], 6, {'field': 'test_1', 'order': 6}),
346
+ # ([0.01, 0.33, 0.14, 0.31], 7, {'field': 'test_2', 'order': 7}),
347
+ # ([0.71, 0.75, 0.91, 0.82], 8, {'field': 'test_3', 'order': 8}),
348
+ # ([0.75, 0.44, 0.38, 0.75], 9, {'field': 'test_1', 'order': 9})])
349
+ # print(ids) # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
350
+ ```
351
+
352
+ ### Query
353
+
354
+
355
+ The default similarity measure for query is cosine. You can specify cosine or L2 to obtain the similarity measure you need.
356
+
357
+ ```python
358
+ collection.search(vector=[0.36, 0.43, 0.56, 0.12], k=10)
359
+ ```
360
+
361
+
362
+
363
+
364
+ (array([ 2, 9, 1, 4, 6, 5, 10, 7, 8, 3]),
365
+ array([1. , 0.92355633, 0.86097705, 0.85727406, 0.81551266,
366
+ 0.813797 , 0.78595245, 0.7741583 , 0.6871773 , 0.34695023]))
367
+
368
+
369
+
370
+ The `query_report_` attribute is the report of the most recent query. When multiple queries are conducted simultaneously, this attribute will only save the report of the last completed query result.
371
+
372
+ ```python
373
+ print(collection.search_report_)
374
+ ```
375
+
376
+
377
+ * - MOST RECENT QUERY REPORT -
378
+ | - Collection Shape: (10, 4)
379
+ | - Query Time: 0.13898 s
380
+ | - Query Distance: cosine
381
+ | - Query K: 10
382
+ | - Top 10 Results ID: [ 2 9 1 4 6 5 10 7 8 3]
383
+ | - Top 10 Results Similarity: [1. 0.92355633 0.86097705 0.85727406 0.81551266 0.813797
384
+ 0.78595245 0.7741583 0.6871773 0.34695023]
385
+ * - END OF REPORT -
386
+
387
+
388
+
389
+ ### Use Filter
390
+
391
+ Using the Filter class for result filtering can maximize Recall.
392
+
393
+ The Filter class now supports `must`, `any`, and `must_not` parameters, all of which only accept list-type argument values.
394
+
395
+ The filtering conditions in `must` must be met, those in `must_not` must not be met.
396
+
397
+ After filtering with `must` and `must_not` conditions, the conditions in `any` will be considered, and at least one of the conditions in `any` must be met.
398
+
399
+ If there is a conflict between the conditions in `any` and those in `must` or `must_not`, the conditions in `any` will be ignored.
400
+
401
+ ```python
402
+ import operator
403
+
404
+ from lynse.core_components.kv_cache.filter import Filter, FieldCondition, MatchField, MatchID
405
+
406
+ collection.search(
407
+ vector=[0.36, 0.43, 0.56, 0.12],
408
+ k=10,
409
+ search_filter=Filter(
410
+ must=[
411
+ FieldCondition(key='field', matcher=MatchField('test_1')), # Support for filtering fields
412
+ ],
413
+ any=[
414
+ FieldCondition(key='order', matcher=MatchField(8, comparator=operator.ge)),
415
+ FieldCondition(key=":match_id:", matcher=MatchID([1, 2, 3, 4, 5])), # Support for filtering IDs
416
+ ],
417
+ must_not=[
418
+ FieldCondition(key=":match_id:", matcher=MatchID([8])),
419
+ FieldCondition(key='order', matcher=MatchField(8, comparator=operator.ge)),
420
+ ]
421
+ )
422
+ )
423
+
424
+ print(collection.search_report_)
425
+ ```
426
+
427
+
428
+ * - MOST RECENT QUERY REPORT -
429
+ | - Collection Shape: (10, 4)
430
+ | - Query Time: 0.09066 s
431
+ | - Query Distance: cosine
432
+ | - Query K: 10
433
+ | - Top 10 Results ID: [2 1]
434
+ | - Top 10 Results Similarity: [1. 0.86097705]
435
+ * - END OF REPORT -
436
+
437
+
438
+
439
+ ### Drop a collection
440
+
441
+ `WARNING: This operation cannot be undone`
442
+
443
+
444
+ ```python
445
+ print("Collection list before dropping:", my_db.show_collections())
446
+ status = my_db.drop_collection("test_collection")
447
+ print("Collection list after dropped:", my_db.show_collections())
448
+ ```
449
+
450
+ Collection list before dropping: ['test_collection']
451
+ {'status': 'success', 'params': {'collection_name': 'test_collection', 'exists': False}}
452
+ Collection list after dropped: []
453
+
454
+
455
+ ## Drop the database
456
+
457
+ `WARNING: This operation cannot be undone`
458
+
459
+
460
+ ```python
461
+ my_db.drop_database()
462
+ my_db
463
+ ```
464
+
465
+
466
+
467
+
468
+ LynseDB remote server at http://localhost:7637 does not exist.
469
+
470
+
471
+
472
+
473
+ ```python
474
+ my_db.database_exists()
475
+ ```
476
+
477
+
478
+
479
+
480
+ {'status': 'success', 'params': {'exists': False}}
481
+
482
+
483
+
484
+ ## What's Next
485
+
486
+ - [Collection's operations](https://github.com/BirchKwok/LynseDB/blob/main/tutorials/collections.ipynb)
487
+ - [Add vectors to collection](https://github.com/BirchKwok/LynseDB/blob/main/tutorials/add_vectors.ipynb)
488
+ - [Using different indexing methods](https://github.com/BirchKwok/LynseDB/blob/main/tutorials/index_mode.ipynb)
489
+ - [Using different distance metric functions](https://github.com/BirchKwok/LynseDB/blob/main/tutorials/distance.ipynb)
490
+ - [Diversified queries](https://github.com/BirchKwok/LynseDB/blob/main/tutorials/queries.ipynb)