vicinity 0.1.0__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.
@@ -0,0 +1,164 @@
1
+ local/*
2
+
3
+ # Byte-compiled / optimized / DLL files
4
+ __pycache__/
5
+ *.py[cod]
6
+ *$py.class
7
+
8
+ # C extensions
9
+ *.so
10
+
11
+ # Distribution / packaging
12
+ .Python
13
+ build/
14
+ develop-eggs/
15
+ dist/
16
+ downloads/
17
+ eggs/
18
+ .eggs/
19
+ lib/
20
+ lib64/
21
+ parts/
22
+ sdist/
23
+ var/
24
+ wheels/
25
+ share/python-wheels/
26
+ *.egg-info/
27
+ .installed.cfg
28
+ *.egg
29
+ MANIFEST
30
+
31
+ # PyInstaller
32
+ # Usually these files are written by a python script from a template
33
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
34
+ *.manifest
35
+ *.spec
36
+
37
+ # Installer logs
38
+ pip-log.txt
39
+ pip-delete-this-directory.txt
40
+
41
+ # Unit test / coverage reports
42
+ htmlcov/
43
+ .tox/
44
+ .nox/
45
+ .coverage
46
+ .coverage.*
47
+ .cache
48
+ nosetests.xml
49
+ coverage.xml
50
+ *.cover
51
+ *.py,cover
52
+ .hypothesis/
53
+ .pytest_cache/
54
+ cover/
55
+
56
+ # Translations
57
+ *.mo
58
+ *.pot
59
+
60
+ # Django stuff:
61
+ *.log
62
+ local_settings.py
63
+ db.sqlite3
64
+ db.sqlite3-journal
65
+
66
+ # Flask stuff:
67
+ instance/
68
+ .webassets-cache
69
+
70
+ # Scrapy stuff:
71
+ .scrapy
72
+
73
+ # Sphinx documentation
74
+ docs/_build/
75
+
76
+ # PyBuilder
77
+ .pybuilder/
78
+ target/
79
+
80
+ # Jupyter Notebook
81
+ .ipynb_checkpoints
82
+
83
+ # IPython
84
+ profile_default/
85
+ ipython_config.py
86
+
87
+ # pyenv
88
+ # For a library or package, you might want to ignore these files since the code is
89
+ # intended to run in multiple environments; otherwise, check them in:
90
+ # .python-version
91
+
92
+ # pipenv
93
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
94
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
95
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
96
+ # install all needed dependencies.
97
+ #Pipfile.lock
98
+
99
+ # poetry
100
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
101
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
102
+ # commonly ignored for libraries.
103
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
104
+ #poetry.lock
105
+
106
+ # pdm
107
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
108
+ #pdm.lock
109
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
110
+ # in version control.
111
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
112
+ .pdm.toml
113
+ .pdm-python
114
+ .pdm-build/
115
+
116
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
117
+ __pypackages__/
118
+
119
+ # Celery stuff
120
+ celerybeat-schedule
121
+ celerybeat.pid
122
+
123
+ # SageMath parsed files
124
+ *.sage.py
125
+
126
+ # Environments
127
+ .env
128
+ .venv
129
+ env/
130
+ venv/
131
+ ENV/
132
+ env.bak/
133
+ venv.bak/
134
+
135
+ # Spyder project settings
136
+ .spyderproject
137
+ .spyproject
138
+
139
+ # Rope project settings
140
+ .ropeproject
141
+
142
+ # mkdocs documentation
143
+ /site
144
+
145
+ # mypy
146
+ .mypy_cache/
147
+ .dmypy.json
148
+ dmypy.json
149
+
150
+ # Pyre type checker
151
+ .pyre/
152
+
153
+ # pytype static type analyzer
154
+ .pytype/
155
+
156
+ # Cython debug symbols
157
+ cython_debug/
158
+
159
+ # PyCharm
160
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
161
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
162
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
163
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
164
+ #.idea/
@@ -0,0 +1,34 @@
1
+ # See https://pre-commit.com for more information
2
+ # See https://pre-commit.com/hooks.html for more hooks
3
+ repos:
4
+ - repo: https://github.com/pre-commit/pre-commit-hooks
5
+ rev: v4.4.0
6
+ hooks:
7
+ - id: check-ast
8
+ description: Simply check whether files parse as valid python.
9
+ - id: trailing-whitespace
10
+ description: Trims trailing whitespace
11
+ - id: end-of-file-fixer
12
+ description: Makes sure files end in a newline and only a newline.
13
+ - id: check-added-large-files
14
+ args: ['--maxkb=5000']
15
+ description: Prevent giant files from being committed.
16
+ - id: check-case-conflict
17
+ description: Check for files with names that would conflict on case-insensitive filesystems like MacOS/Windows.
18
+ - repo: https://github.com/jsh9/pydoclint
19
+ rev: 0.5.3
20
+ hooks:
21
+ - id: pydoclint
22
+ - repo: https://github.com/astral-sh/ruff-pre-commit
23
+ rev: v0.4.10
24
+ hooks:
25
+ - id: ruff
26
+ args: [ --fix ]
27
+ - id: ruff-format
28
+ - repo: local
29
+ hooks:
30
+ - id: mypy
31
+ name: mypy
32
+ entry: mypy
33
+ language: python
34
+ types: [python]
vicinity-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 The Minish Lab
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,15 @@
1
+ clean:
2
+
3
+
4
+ venv:
5
+ uv venv
6
+
7
+ install: venv
8
+ uv sync --all-extras
9
+ uv run pre-commit install
10
+
11
+ fix:
12
+ uv run pre-commit run --all-files
13
+
14
+ test:
15
+ uv run pytest --cov=nearest --cov-report=term-missing
@@ -0,0 +1,200 @@
1
+ Metadata-Version: 2.1
2
+ Name: vicinity
3
+ Version: 0.1.0
4
+ Summary: Lightweight Nearest Neighbors with Flexible Backends
5
+ Author-email: Stéphan Tulkens <stephantul@gmail.com>, Thomas van Dongen <thomas123@live.nl>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2024 The Minish Lab
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Classifier: Development Status :: 4 - Beta
29
+ Classifier: Intended Audience :: Developers
30
+ Classifier: Intended Audience :: Science/Research
31
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
32
+ Classifier: Topic :: Software Development :: Libraries
33
+ Classifier: License :: OSI Approved :: MIT License
34
+ Classifier: Programming Language :: Python :: 3 :: Only
35
+ Classifier: Programming Language :: Python :: 3.10
36
+ Classifier: Programming Language :: Python :: 3.11
37
+ Classifier: Programming Language :: Python :: 3.12
38
+ Requires-Python: >=3.10
39
+ Description-Content-Type: text/markdown
40
+ License-File: LICENSE
41
+ Requires-Dist: numpy
42
+ Requires-Dist: orjson
43
+ Requires-Dist: tqdm
44
+ Provides-Extra: dev
45
+ Requires-Dist: black; extra == "dev"
46
+ Requires-Dist: ipython; extra == "dev"
47
+ Requires-Dist: mypy; extra == "dev"
48
+ Requires-Dist: pre-commit; extra == "dev"
49
+ Requires-Dist: pytest; extra == "dev"
50
+ Requires-Dist: pytest-coverage; extra == "dev"
51
+ Requires-Dist: ruff; extra == "dev"
52
+ Provides-Extra: hnsw
53
+ Requires-Dist: hnswlib; extra == "hnsw"
54
+
55
+ <div align="center">
56
+
57
+ # Vicinity: The Lightweight Vector Store
58
+
59
+ </div>
60
+
61
+ ## Table of contents
62
+
63
+ - [Quickstart](#quickstart)
64
+ - [Main Features](#main-features)
65
+ - [Supported Backends](#supported-backends)
66
+ - [Usage](#usage)
67
+
68
+ Vicinity is the lightest-weight vector store. Just put in some vectors, calculate query vectors, and off you go. It provides a simple and intuitive API for nearest neighbor search, with support for different backends.
69
+
70
+ ## Quickstart
71
+
72
+ Install the package with:
73
+ ```bash
74
+ pip install vicinity
75
+ ```
76
+
77
+ The following code snippet demonstrates how to use Vicinity for nearest neighbor search:
78
+ ```python
79
+ import numpy as np
80
+ from vicinity import Vicinity
81
+ from vicinity.datatypes import Backend
82
+
83
+ # Create some dummy data
84
+ items = ["triforce", "master sword", "hylian shield", "boomerang", "hookshot"]
85
+ vectors = np.random.rand(len(items), 128)
86
+
87
+ # Initialize the Vicinity instance (using the basic backend)
88
+ vicinity = Vicinity.from_vectors_and_items(vectors=vectors, items=items, backend_type=Backend.BASIC)
89
+
90
+ # Query for nearest neighbors with a top-k search
91
+ query_vector = np.random.rand(128)
92
+ results = vicinity.query([query_vector], k=3)
93
+
94
+ # Query for nearest neighbors with a threshold search
95
+ results = vicinity.query_threshold([query_vector], threshold=0.9)
96
+
97
+ # Save the vector store
98
+ vicinity.save('my_vector_store')
99
+
100
+ # Load the vector store
101
+ vicinity = Vicinity.load('my_vector_store')
102
+ ```
103
+
104
+ ## Main Features
105
+ Vicinity provides the following features:
106
+ - Lightweight: Minimal dependencies and fast performance.
107
+ - Flexible Backend Support: Use different backends for vector storage and search.
108
+ - Dynamic Updates: Insert and delete items in the vector store.
109
+ - Serialization: Save and load vector stores for persistence.
110
+ - Easy to Use: Simple and intuitive API.
111
+
112
+ ## Supported Backends
113
+ The following backends are supported:
114
+ - `BASIC`: A simple flat index for vector storage and search.
115
+ - `HNSW`: Hierarchical Navigable Small World Graph for approximate nearest neighbor search.
116
+
117
+ ## Usage
118
+
119
+ <details>
120
+ <summary> Creating a Vector Store
121
+ </summary>
122
+ <br>
123
+
124
+ You can create a Vicinity instance by providing items and their corresponding vectors:
125
+
126
+
127
+ ```python
128
+ from vicinity import Vicinity
129
+ import numpy as np
130
+
131
+ items = ["triforce", "master sword", "hylian shield", "boomerang", "hookshot"]
132
+ vectors = np.random.rand(len(items), 128)
133
+
134
+ vicinity = Vicinity.from_vectors_and_items(vectors=vectors, items=items)
135
+ ```
136
+
137
+ </details>
138
+
139
+ <details>
140
+ <summary> Querying
141
+ </summary>
142
+ <br>
143
+
144
+ Find the k nearest neighbors for a given vector:
145
+
146
+ ```python
147
+ query_vector = np.random.rand(128)
148
+ results = vicinity.query([query_vector], k=3)
149
+ ```
150
+
151
+ Find all neighbors within a given threshold:
152
+
153
+ ```python
154
+ query_vector = np.random.rand(128)
155
+ results = vicinity.query_threshold([query_vector], threshold=0.9)
156
+ ```
157
+ </details>
158
+
159
+ <details>
160
+
161
+ <summary> Inserting and Deleting Items
162
+ </summary>
163
+ <br>
164
+
165
+ Insert new items:
166
+
167
+ ```python
168
+ new_items = ["ocarina", "bow"]
169
+ new_vectors = np.random.rand(2, 128)
170
+ vicinity.insert(new_items, new_vectors)
171
+ ```
172
+
173
+ Delete items:
174
+
175
+ ```python
176
+ vicinity.delete(["hookshot"])
177
+ ```
178
+ </details>
179
+
180
+ <details>
181
+ <summary> Saving and Loading
182
+ </summary>
183
+ <br>
184
+
185
+ Save the vector store:
186
+
187
+ ```python
188
+ vicinity.save('my_vector_store')
189
+ ```
190
+
191
+ Load the vector store:
192
+
193
+ ```python
194
+ vicinity = Vicinity.load('my_vector_store')
195
+ ```
196
+ </details>
197
+
198
+ ## License
199
+
200
+ MIT
@@ -0,0 +1,146 @@
1
+ <div align="center">
2
+
3
+ # Vicinity: The Lightweight Vector Store
4
+
5
+ </div>
6
+
7
+ ## Table of contents
8
+
9
+ - [Quickstart](#quickstart)
10
+ - [Main Features](#main-features)
11
+ - [Supported Backends](#supported-backends)
12
+ - [Usage](#usage)
13
+
14
+ Vicinity is the lightest-weight vector store. Just put in some vectors, calculate query vectors, and off you go. It provides a simple and intuitive API for nearest neighbor search, with support for different backends.
15
+
16
+ ## Quickstart
17
+
18
+ Install the package with:
19
+ ```bash
20
+ pip install vicinity
21
+ ```
22
+
23
+ The following code snippet demonstrates how to use Vicinity for nearest neighbor search:
24
+ ```python
25
+ import numpy as np
26
+ from vicinity import Vicinity
27
+ from vicinity.datatypes import Backend
28
+
29
+ # Create some dummy data
30
+ items = ["triforce", "master sword", "hylian shield", "boomerang", "hookshot"]
31
+ vectors = np.random.rand(len(items), 128)
32
+
33
+ # Initialize the Vicinity instance (using the basic backend)
34
+ vicinity = Vicinity.from_vectors_and_items(vectors=vectors, items=items, backend_type=Backend.BASIC)
35
+
36
+ # Query for nearest neighbors with a top-k search
37
+ query_vector = np.random.rand(128)
38
+ results = vicinity.query([query_vector], k=3)
39
+
40
+ # Query for nearest neighbors with a threshold search
41
+ results = vicinity.query_threshold([query_vector], threshold=0.9)
42
+
43
+ # Save the vector store
44
+ vicinity.save('my_vector_store')
45
+
46
+ # Load the vector store
47
+ vicinity = Vicinity.load('my_vector_store')
48
+ ```
49
+
50
+ ## Main Features
51
+ Vicinity provides the following features:
52
+ - Lightweight: Minimal dependencies and fast performance.
53
+ - Flexible Backend Support: Use different backends for vector storage and search.
54
+ - Dynamic Updates: Insert and delete items in the vector store.
55
+ - Serialization: Save and load vector stores for persistence.
56
+ - Easy to Use: Simple and intuitive API.
57
+
58
+ ## Supported Backends
59
+ The following backends are supported:
60
+ - `BASIC`: A simple flat index for vector storage and search.
61
+ - `HNSW`: Hierarchical Navigable Small World Graph for approximate nearest neighbor search.
62
+
63
+ ## Usage
64
+
65
+ <details>
66
+ <summary> Creating a Vector Store
67
+ </summary>
68
+ <br>
69
+
70
+ You can create a Vicinity instance by providing items and their corresponding vectors:
71
+
72
+
73
+ ```python
74
+ from vicinity import Vicinity
75
+ import numpy as np
76
+
77
+ items = ["triforce", "master sword", "hylian shield", "boomerang", "hookshot"]
78
+ vectors = np.random.rand(len(items), 128)
79
+
80
+ vicinity = Vicinity.from_vectors_and_items(vectors=vectors, items=items)
81
+ ```
82
+
83
+ </details>
84
+
85
+ <details>
86
+ <summary> Querying
87
+ </summary>
88
+ <br>
89
+
90
+ Find the k nearest neighbors for a given vector:
91
+
92
+ ```python
93
+ query_vector = np.random.rand(128)
94
+ results = vicinity.query([query_vector], k=3)
95
+ ```
96
+
97
+ Find all neighbors within a given threshold:
98
+
99
+ ```python
100
+ query_vector = np.random.rand(128)
101
+ results = vicinity.query_threshold([query_vector], threshold=0.9)
102
+ ```
103
+ </details>
104
+
105
+ <details>
106
+
107
+ <summary> Inserting and Deleting Items
108
+ </summary>
109
+ <br>
110
+
111
+ Insert new items:
112
+
113
+ ```python
114
+ new_items = ["ocarina", "bow"]
115
+ new_vectors = np.random.rand(2, 128)
116
+ vicinity.insert(new_items, new_vectors)
117
+ ```
118
+
119
+ Delete items:
120
+
121
+ ```python
122
+ vicinity.delete(["hookshot"])
123
+ ```
124
+ </details>
125
+
126
+ <details>
127
+ <summary> Saving and Loading
128
+ </summary>
129
+ <br>
130
+
131
+ Save the vector store:
132
+
133
+ ```python
134
+ vicinity.save('my_vector_store')
135
+ ```
136
+
137
+ Load the vector store:
138
+
139
+ ```python
140
+ vicinity = Vicinity.load('my_vector_store')
141
+ ```
142
+ </details>
143
+
144
+ ## License
145
+
146
+ MIT
@@ -0,0 +1,94 @@
1
+ [project]
2
+ name = "vicinity"
3
+ description = "Lightweight Nearest Neighbors with Flexible Backends"
4
+ readme = { file = "README.md", content-type = "text/markdown" }
5
+ dynamic = ["version"]
6
+ requires-python = ">=3.10"
7
+ license = { file = "LICENSE" }
8
+ authors = [{ name = "Stéphan Tulkens", email = "stephantul@gmail.com"}, {name = "Thomas van Dongen", email = "thomas123@live.nl"}]
9
+
10
+ classifiers = [
11
+ "Development Status :: 4 - Beta",
12
+ "Intended Audience :: Developers",
13
+ "Intended Audience :: Science/Research",
14
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
15
+ "Topic :: Software Development :: Libraries",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Programming Language :: Python :: 3 :: Only",
18
+ "Programming Language :: Python :: 3.10",
19
+ "Programming Language :: Python :: 3.11",
20
+ "Programming Language :: Python :: 3.12",
21
+ ]
22
+
23
+ dependencies = [
24
+ "numpy",
25
+ "orjson",
26
+ "tqdm"
27
+ ]
28
+
29
+ [build-system]
30
+ requires = ["setuptools>=64", "setuptools_scm>=8"]
31
+ build-backend = "setuptools.build_meta"
32
+
33
+ [project.optional-dependencies]
34
+ dev = [
35
+ "black",
36
+ "ipython",
37
+ "mypy",
38
+ "pre-commit",
39
+ "pytest",
40
+ "pytest-coverage",
41
+ "ruff",
42
+ ]
43
+ hnsw = ["hnswlib"]
44
+
45
+ [tool.ruff]
46
+ exclude = [".venv/"]
47
+ line-length = 120
48
+ target-version = "py310"
49
+
50
+ [tool.ruff.lint]
51
+ select = [
52
+ # Annotations: Enforce type annotations
53
+ "ANN",
54
+ # Complexity: Enforce a maximum cyclomatic complexity
55
+ "C90",
56
+ # Pydocstyle: Enforce docstrings
57
+ "D",
58
+ # Isort: Enforce import order
59
+ "I",
60
+ # Numpy: Enforce numpy style
61
+ "NPY",
62
+ # Print: Forbid print statements
63
+ "T20",
64
+ ]
65
+ ignore = [
66
+ # Allow self and cls to be untyped, and allow Any type
67
+ "ANN101", "ANN102", "ANN401",
68
+ # Pydocstyle ignores
69
+ "D100", "D101", "D104", "D203", "D212", "D401",
70
+ # Allow use of f-strings in logging
71
+ "G004"
72
+ ]
73
+
74
+ [tool.pydoclint]
75
+ style = "sphinx"
76
+ exclude = "test_"
77
+ allow-init-docstring = true
78
+ arg-type-hints-in-docstring = false
79
+ check-return-types = false
80
+ require-return-section-when-returning-nothing = false
81
+
82
+ [tool.mypy]
83
+ python_version = "3.10"
84
+ warn_unused_configs = true
85
+ ignore_missing_imports = true
86
+
87
+ [tool.setuptools]
88
+ packages = ["vicinity"]
89
+
90
+ [tool.setuptools_scm]
91
+ # can be empty if no extra settings are needed, presence enables setuptools_scm
92
+
93
+ [tool.setuptools.dynamic]
94
+ version = {attr = "vicinity.version.__version__"}
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+