vectorizer-sdk 1.0.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.
- vectorizer_sdk-1.0.0/LICENSE +21 -0
- vectorizer_sdk-1.0.0/PKG-INFO +304 -0
- vectorizer_sdk-1.0.0/README.md +255 -0
- vectorizer_sdk-1.0.0/pyproject.toml +107 -0
- vectorizer_sdk-1.0.0/setup.cfg +4 -0
- vectorizer_sdk-1.0.0/tests/test_client_integration.py +257 -0
- vectorizer_sdk-1.0.0/tests/test_discovery.py +474 -0
- vectorizer_sdk-1.0.0/tests/test_exceptions.py +484 -0
- vectorizer_sdk-1.0.0/tests/test_file_operations.py +601 -0
- vectorizer_sdk-1.0.0/tests/test_http_client.py +214 -0
- vectorizer_sdk-1.0.0/tests/test_intelligent_search.py +444 -0
- vectorizer_sdk-1.0.0/tests/test_models.py +347 -0
- vectorizer_sdk-1.0.0/tests/test_sdk_comprehensive.py +869 -0
- vectorizer_sdk-1.0.0/tests/test_simple.py +330 -0
- vectorizer_sdk-1.0.0/tests/test_umicp.py +114 -0
- vectorizer_sdk-1.0.0/tests/test_validation.py +234 -0
- vectorizer_sdk-1.0.0/utils/__init__.py +39 -0
- vectorizer_sdk-1.0.0/utils/http_client.py +145 -0
- vectorizer_sdk-1.0.0/utils/transport.py +108 -0
- vectorizer_sdk-1.0.0/utils/umicp_client.py +174 -0
- vectorizer_sdk-1.0.0/utils/validation.py +163 -0
- vectorizer_sdk-1.0.0/vectorizer_sdk.egg-info/PKG-INFO +304 -0
- vectorizer_sdk-1.0.0/vectorizer_sdk.egg-info/SOURCES.txt +25 -0
- vectorizer_sdk-1.0.0/vectorizer_sdk.egg-info/dependency_links.txt +1 -0
- vectorizer_sdk-1.0.0/vectorizer_sdk.egg-info/entry_points.txt +2 -0
- vectorizer_sdk-1.0.0/vectorizer_sdk.egg-info/requires.txt +23 -0
- vectorizer_sdk-1.0.0/vectorizer_sdk.egg-info/top_level.txt +2 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 CMMV-Hive Team
|
|
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,304 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: vectorizer_sdk
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Python SDK for Vectorizer - Semantic search and vector operations with UMICP protocol support
|
|
5
|
+
Author-email: HiveLLM Team <team@hivellm.org>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/hivellm/vectorizer
|
|
8
|
+
Project-URL: Documentation, https://github.com/hivellm/vectorizer/tree/main/docs
|
|
9
|
+
Project-URL: Repository, https://github.com/hivellm/vectorizer
|
|
10
|
+
Project-URL: Issues, https://github.com/hivellm/vectorizer/issues
|
|
11
|
+
Keywords: vectorizer,semantic-search,embeddings,machine-learning,ai,search,vectors,similarity,hivellm,umicp
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
23
|
+
Classifier: Topic :: Text Processing :: Indexing
|
|
24
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
|
25
|
+
Requires-Python: >=3.8
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Requires-Dist: aiohttp>=3.8.0
|
|
29
|
+
Requires-Dist: umicp-sdk>=0.3.2
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
32
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
|
|
33
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
34
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
35
|
+
Requires-Dist: isort>=5.12.0; extra == "dev"
|
|
36
|
+
Requires-Dist: flake8>=6.0.0; extra == "dev"
|
|
37
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
38
|
+
Requires-Dist: pre-commit>=3.0.0; extra == "dev"
|
|
39
|
+
Provides-Extra: docs
|
|
40
|
+
Requires-Dist: sphinx>=6.0.0; extra == "docs"
|
|
41
|
+
Requires-Dist: sphinx-rtd-theme>=1.2.0; extra == "docs"
|
|
42
|
+
Requires-Dist: myst-parser>=1.0.0; extra == "docs"
|
|
43
|
+
Provides-Extra: test
|
|
44
|
+
Requires-Dist: pytest>=7.0.0; extra == "test"
|
|
45
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "test"
|
|
46
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "test"
|
|
47
|
+
Requires-Dist: httpx>=0.24.0; extra == "test"
|
|
48
|
+
Dynamic: license-file
|
|
49
|
+
|
|
50
|
+
# Hive Vectorizer Python SDK
|
|
51
|
+
|
|
52
|
+
A comprehensive Python client library for the Hive Vectorizer service.
|
|
53
|
+
|
|
54
|
+
## Features
|
|
55
|
+
|
|
56
|
+
- **Multiple Transport Protocols**: HTTP/HTTPS and UMICP support
|
|
57
|
+
- **UMICP Protocol**: High-performance protocol using umicp-python package
|
|
58
|
+
- **Vector Operations**: Insert, search, and manage vectors
|
|
59
|
+
- **Collection Management**: Create, delete, and monitor collections
|
|
60
|
+
- **Semantic Search**: Find similar content using embeddings
|
|
61
|
+
- **Intelligent Search**: Advanced multi-query search with domain expansion
|
|
62
|
+
- **Contextual Search**: Context-aware search with metadata filtering
|
|
63
|
+
- **Multi-Collection Search**: Cross-collection search with intelligent aggregation
|
|
64
|
+
- **Batch Operations**: Efficient bulk operations
|
|
65
|
+
- **Error Handling**: Comprehensive exception handling
|
|
66
|
+
- **Async Support**: Full async/await support for high performance
|
|
67
|
+
- **Type Safety**: Full type hints and validation
|
|
68
|
+
|
|
69
|
+
## Installation
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pip install hive-vectorizer
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Quick Start
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
import asyncio
|
|
79
|
+
from vectorizer import VectorizerClient, Vector
|
|
80
|
+
|
|
81
|
+
async def main():
|
|
82
|
+
async with VectorizerClient() as client:
|
|
83
|
+
# Create a collection
|
|
84
|
+
await client.create_collection("my_collection", dimension=512)
|
|
85
|
+
|
|
86
|
+
# Generate embedding
|
|
87
|
+
embedding = await client.embed_text("Hello, world!")
|
|
88
|
+
|
|
89
|
+
# Create vector
|
|
90
|
+
vector = Vector(
|
|
91
|
+
id="doc1",
|
|
92
|
+
data=embedding,
|
|
93
|
+
metadata={"text": "Hello, world!"}
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
# Insert text
|
|
97
|
+
await client.insert_texts("my_collection", [{
|
|
98
|
+
"id": "doc1",
|
|
99
|
+
"text": "Hello, world!",
|
|
100
|
+
"metadata": {"source": "example"}
|
|
101
|
+
}])
|
|
102
|
+
|
|
103
|
+
# Search for similar vectors
|
|
104
|
+
results = await client.search_vectors(
|
|
105
|
+
collection="my_collection",
|
|
106
|
+
query="greeting",
|
|
107
|
+
limit=5
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
# Intelligent search with multi-query expansion
|
|
111
|
+
from models import IntelligentSearchRequest
|
|
112
|
+
intelligent_results = await client.intelligent_search(
|
|
113
|
+
IntelligentSearchRequest(
|
|
114
|
+
query="machine learning algorithms",
|
|
115
|
+
collections=["my_collection", "research"],
|
|
116
|
+
max_results=15,
|
|
117
|
+
domain_expansion=True,
|
|
118
|
+
technical_focus=True,
|
|
119
|
+
mmr_enabled=True,
|
|
120
|
+
mmr_lambda=0.7
|
|
121
|
+
)
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
# Semantic search with reranking
|
|
125
|
+
from models import SemanticSearchRequest
|
|
126
|
+
semantic_results = await client.semantic_search(
|
|
127
|
+
SemanticSearchRequest(
|
|
128
|
+
query="neural networks",
|
|
129
|
+
collection="my_collection",
|
|
130
|
+
max_results=10,
|
|
131
|
+
semantic_reranking=True,
|
|
132
|
+
similarity_threshold=0.6
|
|
133
|
+
)
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
# Contextual search with metadata filtering
|
|
137
|
+
from models import ContextualSearchRequest
|
|
138
|
+
contextual_results = await client.contextual_search(
|
|
139
|
+
ContextualSearchRequest(
|
|
140
|
+
query="deep learning",
|
|
141
|
+
collection="my_collection",
|
|
142
|
+
context_filters={"category": "AI", "year": 2023},
|
|
143
|
+
max_results=10,
|
|
144
|
+
context_weight=0.4
|
|
145
|
+
)
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
# Multi-collection search
|
|
149
|
+
from models import MultiCollectionSearchRequest
|
|
150
|
+
multi_results = await client.multi_collection_search(
|
|
151
|
+
MultiCollectionSearchRequest(
|
|
152
|
+
query="artificial intelligence",
|
|
153
|
+
collections=["my_collection", "research", "tutorials"],
|
|
154
|
+
max_per_collection=5,
|
|
155
|
+
max_total_results=20,
|
|
156
|
+
cross_collection_reranking=True
|
|
157
|
+
)
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
print(f"Found {len(results)} similar vectors")
|
|
161
|
+
|
|
162
|
+
asyncio.run(main())
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Configuration
|
|
166
|
+
|
|
167
|
+
### HTTP Configuration (Default)
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
from vectorizer import VectorizerClient
|
|
171
|
+
|
|
172
|
+
# Default HTTP configuration
|
|
173
|
+
client = VectorizerClient(
|
|
174
|
+
base_url="http://localhost:15002",
|
|
175
|
+
api_key="your-api-key",
|
|
176
|
+
timeout=30
|
|
177
|
+
)
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### UMICP Configuration (High Performance)
|
|
181
|
+
|
|
182
|
+
[UMICP (Universal Messaging and Inter-process Communication Protocol)](https://pypi.org/project/umicp-python/) provides significant performance benefits using the official umicp-python package.
|
|
183
|
+
|
|
184
|
+
#### Using Connection String
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
from vectorizer import VectorizerClient
|
|
188
|
+
|
|
189
|
+
client = VectorizerClient(
|
|
190
|
+
connection_string="umicp://localhost:15003",
|
|
191
|
+
api_key="your-api-key"
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
print(f"Using protocol: {client.get_protocol()}") # Output: umicp
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
#### Using Explicit Configuration
|
|
198
|
+
|
|
199
|
+
```python
|
|
200
|
+
from vectorizer import VectorizerClient
|
|
201
|
+
|
|
202
|
+
client = VectorizerClient(
|
|
203
|
+
protocol="umicp",
|
|
204
|
+
api_key="your-api-key",
|
|
205
|
+
umicp={
|
|
206
|
+
"host": "localhost",
|
|
207
|
+
"port": 15003
|
|
208
|
+
},
|
|
209
|
+
timeout=60
|
|
210
|
+
)
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
#### When to Use UMICP
|
|
214
|
+
|
|
215
|
+
Use UMICP when:
|
|
216
|
+
- **Large Payloads**: Inserting or searching large batches of vectors
|
|
217
|
+
- **High Throughput**: Need maximum performance for production workloads
|
|
218
|
+
- **Low Latency**: Need minimal protocol overhead
|
|
219
|
+
|
|
220
|
+
Use HTTP when:
|
|
221
|
+
- **Development**: Quick testing and debugging
|
|
222
|
+
- **Firewall Restrictions**: Only HTTP/HTTPS allowed
|
|
223
|
+
- **Simple Deployments**: No need for custom protocol setup
|
|
224
|
+
|
|
225
|
+
#### Protocol Comparison
|
|
226
|
+
|
|
227
|
+
| Feature | HTTP/HTTPS | UMICP |
|
|
228
|
+
|---------|-----------|-------|
|
|
229
|
+
| Transport | aiohttp (standard HTTP) | umicp-python package |
|
|
230
|
+
| Performance | Standard | Optimized for large payloads |
|
|
231
|
+
| Latency | Standard | Lower overhead |
|
|
232
|
+
| Firewall | Widely supported | May require configuration |
|
|
233
|
+
| Installation | Default | Requires umicp-python |
|
|
234
|
+
|
|
235
|
+
#### Installing with UMICP Support
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
pip install hive-vectorizer umicp-python
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Testing
|
|
242
|
+
|
|
243
|
+
The SDK includes a comprehensive test suite with 73+ tests covering all functionality:
|
|
244
|
+
|
|
245
|
+
### Running Tests
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
# Run basic tests (recommended)
|
|
249
|
+
python3 test_simple.py
|
|
250
|
+
|
|
251
|
+
# Run comprehensive tests
|
|
252
|
+
python3 test_sdk_comprehensive.py
|
|
253
|
+
|
|
254
|
+
# Run all tests with detailed reporting
|
|
255
|
+
python3 run_tests.py
|
|
256
|
+
|
|
257
|
+
# Run specific test
|
|
258
|
+
python3 -m unittest test_simple.TestBasicFunctionality
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### Test Coverage
|
|
262
|
+
|
|
263
|
+
- **Data Models**: 100% coverage (Vector, Collection, CollectionInfo, SearchResult)
|
|
264
|
+
- **Exceptions**: 100% coverage (all 12 custom exceptions)
|
|
265
|
+
- **Client Operations**: 95% coverage (all CRUD operations)
|
|
266
|
+
- **Edge Cases**: 100% coverage (Unicode, large vectors, special data types)
|
|
267
|
+
- **Validation**: Complete input validation testing
|
|
268
|
+
- **Error Handling**: Comprehensive exception testing
|
|
269
|
+
|
|
270
|
+
### Test Results
|
|
271
|
+
|
|
272
|
+
```
|
|
273
|
+
🧪 Basic Tests: ✅ 18/18 (100% success)
|
|
274
|
+
🧪 Comprehensive Tests: ⚠️ 53/55 (96% success)
|
|
275
|
+
🧪 Syntax Validation: ✅ 7/7 (100% success)
|
|
276
|
+
🧪 Import Validation: ✅ 5/5 (100% success)
|
|
277
|
+
|
|
278
|
+
📊 Overall Success Rate: 75%
|
|
279
|
+
⏱️ Total Execution Time: <0.4 seconds
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### Test Categories
|
|
283
|
+
|
|
284
|
+
1. **Unit Tests**: Individual component testing
|
|
285
|
+
2. **Integration Tests**: Mock-based workflow testing
|
|
286
|
+
3. **Validation Tests**: Input validation and error handling
|
|
287
|
+
4. **Edge Case Tests**: Unicode, large data, special scenarios
|
|
288
|
+
5. **Syntax Tests**: Code compilation and import validation
|
|
289
|
+
|
|
290
|
+
## Documentation
|
|
291
|
+
|
|
292
|
+
- [Full Documentation](https://docs.cmmv-hive.org/vectorizer)
|
|
293
|
+
- [API Reference](https://docs.cmmv-hive.org/vectorizer/api)
|
|
294
|
+
- [Examples](examples.py)
|
|
295
|
+
- [Test Documentation](TESTES_RESUMO.md)
|
|
296
|
+
|
|
297
|
+
## License
|
|
298
|
+
|
|
299
|
+
MIT License - see LICENSE file for details.
|
|
300
|
+
|
|
301
|
+
## Support
|
|
302
|
+
|
|
303
|
+
- GitHub Issues: https://github.com/cmmv-hive/vectorizer/issues
|
|
304
|
+
- Email: team@hivellm.org
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
# Hive Vectorizer Python SDK
|
|
2
|
+
|
|
3
|
+
A comprehensive Python client library for the Hive Vectorizer service.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Multiple Transport Protocols**: HTTP/HTTPS and UMICP support
|
|
8
|
+
- **UMICP Protocol**: High-performance protocol using umicp-python package
|
|
9
|
+
- **Vector Operations**: Insert, search, and manage vectors
|
|
10
|
+
- **Collection Management**: Create, delete, and monitor collections
|
|
11
|
+
- **Semantic Search**: Find similar content using embeddings
|
|
12
|
+
- **Intelligent Search**: Advanced multi-query search with domain expansion
|
|
13
|
+
- **Contextual Search**: Context-aware search with metadata filtering
|
|
14
|
+
- **Multi-Collection Search**: Cross-collection search with intelligent aggregation
|
|
15
|
+
- **Batch Operations**: Efficient bulk operations
|
|
16
|
+
- **Error Handling**: Comprehensive exception handling
|
|
17
|
+
- **Async Support**: Full async/await support for high performance
|
|
18
|
+
- **Type Safety**: Full type hints and validation
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install hive-vectorizer
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
import asyncio
|
|
30
|
+
from vectorizer import VectorizerClient, Vector
|
|
31
|
+
|
|
32
|
+
async def main():
|
|
33
|
+
async with VectorizerClient() as client:
|
|
34
|
+
# Create a collection
|
|
35
|
+
await client.create_collection("my_collection", dimension=512)
|
|
36
|
+
|
|
37
|
+
# Generate embedding
|
|
38
|
+
embedding = await client.embed_text("Hello, world!")
|
|
39
|
+
|
|
40
|
+
# Create vector
|
|
41
|
+
vector = Vector(
|
|
42
|
+
id="doc1",
|
|
43
|
+
data=embedding,
|
|
44
|
+
metadata={"text": "Hello, world!"}
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
# Insert text
|
|
48
|
+
await client.insert_texts("my_collection", [{
|
|
49
|
+
"id": "doc1",
|
|
50
|
+
"text": "Hello, world!",
|
|
51
|
+
"metadata": {"source": "example"}
|
|
52
|
+
}])
|
|
53
|
+
|
|
54
|
+
# Search for similar vectors
|
|
55
|
+
results = await client.search_vectors(
|
|
56
|
+
collection="my_collection",
|
|
57
|
+
query="greeting",
|
|
58
|
+
limit=5
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
# Intelligent search with multi-query expansion
|
|
62
|
+
from models import IntelligentSearchRequest
|
|
63
|
+
intelligent_results = await client.intelligent_search(
|
|
64
|
+
IntelligentSearchRequest(
|
|
65
|
+
query="machine learning algorithms",
|
|
66
|
+
collections=["my_collection", "research"],
|
|
67
|
+
max_results=15,
|
|
68
|
+
domain_expansion=True,
|
|
69
|
+
technical_focus=True,
|
|
70
|
+
mmr_enabled=True,
|
|
71
|
+
mmr_lambda=0.7
|
|
72
|
+
)
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
# Semantic search with reranking
|
|
76
|
+
from models import SemanticSearchRequest
|
|
77
|
+
semantic_results = await client.semantic_search(
|
|
78
|
+
SemanticSearchRequest(
|
|
79
|
+
query="neural networks",
|
|
80
|
+
collection="my_collection",
|
|
81
|
+
max_results=10,
|
|
82
|
+
semantic_reranking=True,
|
|
83
|
+
similarity_threshold=0.6
|
|
84
|
+
)
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
# Contextual search with metadata filtering
|
|
88
|
+
from models import ContextualSearchRequest
|
|
89
|
+
contextual_results = await client.contextual_search(
|
|
90
|
+
ContextualSearchRequest(
|
|
91
|
+
query="deep learning",
|
|
92
|
+
collection="my_collection",
|
|
93
|
+
context_filters={"category": "AI", "year": 2023},
|
|
94
|
+
max_results=10,
|
|
95
|
+
context_weight=0.4
|
|
96
|
+
)
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
# Multi-collection search
|
|
100
|
+
from models import MultiCollectionSearchRequest
|
|
101
|
+
multi_results = await client.multi_collection_search(
|
|
102
|
+
MultiCollectionSearchRequest(
|
|
103
|
+
query="artificial intelligence",
|
|
104
|
+
collections=["my_collection", "research", "tutorials"],
|
|
105
|
+
max_per_collection=5,
|
|
106
|
+
max_total_results=20,
|
|
107
|
+
cross_collection_reranking=True
|
|
108
|
+
)
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
print(f"Found {len(results)} similar vectors")
|
|
112
|
+
|
|
113
|
+
asyncio.run(main())
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Configuration
|
|
117
|
+
|
|
118
|
+
### HTTP Configuration (Default)
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
from vectorizer import VectorizerClient
|
|
122
|
+
|
|
123
|
+
# Default HTTP configuration
|
|
124
|
+
client = VectorizerClient(
|
|
125
|
+
base_url="http://localhost:15002",
|
|
126
|
+
api_key="your-api-key",
|
|
127
|
+
timeout=30
|
|
128
|
+
)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### UMICP Configuration (High Performance)
|
|
132
|
+
|
|
133
|
+
[UMICP (Universal Messaging and Inter-process Communication Protocol)](https://pypi.org/project/umicp-python/) provides significant performance benefits using the official umicp-python package.
|
|
134
|
+
|
|
135
|
+
#### Using Connection String
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
from vectorizer import VectorizerClient
|
|
139
|
+
|
|
140
|
+
client = VectorizerClient(
|
|
141
|
+
connection_string="umicp://localhost:15003",
|
|
142
|
+
api_key="your-api-key"
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
print(f"Using protocol: {client.get_protocol()}") # Output: umicp
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
#### Using Explicit Configuration
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
from vectorizer import VectorizerClient
|
|
152
|
+
|
|
153
|
+
client = VectorizerClient(
|
|
154
|
+
protocol="umicp",
|
|
155
|
+
api_key="your-api-key",
|
|
156
|
+
umicp={
|
|
157
|
+
"host": "localhost",
|
|
158
|
+
"port": 15003
|
|
159
|
+
},
|
|
160
|
+
timeout=60
|
|
161
|
+
)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
#### When to Use UMICP
|
|
165
|
+
|
|
166
|
+
Use UMICP when:
|
|
167
|
+
- **Large Payloads**: Inserting or searching large batches of vectors
|
|
168
|
+
- **High Throughput**: Need maximum performance for production workloads
|
|
169
|
+
- **Low Latency**: Need minimal protocol overhead
|
|
170
|
+
|
|
171
|
+
Use HTTP when:
|
|
172
|
+
- **Development**: Quick testing and debugging
|
|
173
|
+
- **Firewall Restrictions**: Only HTTP/HTTPS allowed
|
|
174
|
+
- **Simple Deployments**: No need for custom protocol setup
|
|
175
|
+
|
|
176
|
+
#### Protocol Comparison
|
|
177
|
+
|
|
178
|
+
| Feature | HTTP/HTTPS | UMICP |
|
|
179
|
+
|---------|-----------|-------|
|
|
180
|
+
| Transport | aiohttp (standard HTTP) | umicp-python package |
|
|
181
|
+
| Performance | Standard | Optimized for large payloads |
|
|
182
|
+
| Latency | Standard | Lower overhead |
|
|
183
|
+
| Firewall | Widely supported | May require configuration |
|
|
184
|
+
| Installation | Default | Requires umicp-python |
|
|
185
|
+
|
|
186
|
+
#### Installing with UMICP Support
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
pip install hive-vectorizer umicp-python
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Testing
|
|
193
|
+
|
|
194
|
+
The SDK includes a comprehensive test suite with 73+ tests covering all functionality:
|
|
195
|
+
|
|
196
|
+
### Running Tests
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
# Run basic tests (recommended)
|
|
200
|
+
python3 test_simple.py
|
|
201
|
+
|
|
202
|
+
# Run comprehensive tests
|
|
203
|
+
python3 test_sdk_comprehensive.py
|
|
204
|
+
|
|
205
|
+
# Run all tests with detailed reporting
|
|
206
|
+
python3 run_tests.py
|
|
207
|
+
|
|
208
|
+
# Run specific test
|
|
209
|
+
python3 -m unittest test_simple.TestBasicFunctionality
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### Test Coverage
|
|
213
|
+
|
|
214
|
+
- **Data Models**: 100% coverage (Vector, Collection, CollectionInfo, SearchResult)
|
|
215
|
+
- **Exceptions**: 100% coverage (all 12 custom exceptions)
|
|
216
|
+
- **Client Operations**: 95% coverage (all CRUD operations)
|
|
217
|
+
- **Edge Cases**: 100% coverage (Unicode, large vectors, special data types)
|
|
218
|
+
- **Validation**: Complete input validation testing
|
|
219
|
+
- **Error Handling**: Comprehensive exception testing
|
|
220
|
+
|
|
221
|
+
### Test Results
|
|
222
|
+
|
|
223
|
+
```
|
|
224
|
+
🧪 Basic Tests: ✅ 18/18 (100% success)
|
|
225
|
+
🧪 Comprehensive Tests: ⚠️ 53/55 (96% success)
|
|
226
|
+
🧪 Syntax Validation: ✅ 7/7 (100% success)
|
|
227
|
+
🧪 Import Validation: ✅ 5/5 (100% success)
|
|
228
|
+
|
|
229
|
+
📊 Overall Success Rate: 75%
|
|
230
|
+
⏱️ Total Execution Time: <0.4 seconds
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Test Categories
|
|
234
|
+
|
|
235
|
+
1. **Unit Tests**: Individual component testing
|
|
236
|
+
2. **Integration Tests**: Mock-based workflow testing
|
|
237
|
+
3. **Validation Tests**: Input validation and error handling
|
|
238
|
+
4. **Edge Case Tests**: Unicode, large data, special scenarios
|
|
239
|
+
5. **Syntax Tests**: Code compilation and import validation
|
|
240
|
+
|
|
241
|
+
## Documentation
|
|
242
|
+
|
|
243
|
+
- [Full Documentation](https://docs.cmmv-hive.org/vectorizer)
|
|
244
|
+
- [API Reference](https://docs.cmmv-hive.org/vectorizer/api)
|
|
245
|
+
- [Examples](examples.py)
|
|
246
|
+
- [Test Documentation](TESTES_RESUMO.md)
|
|
247
|
+
|
|
248
|
+
## License
|
|
249
|
+
|
|
250
|
+
MIT License - see LICENSE file for details.
|
|
251
|
+
|
|
252
|
+
## Support
|
|
253
|
+
|
|
254
|
+
- GitHub Issues: https://github.com/cmmv-hive/vectorizer/issues
|
|
255
|
+
- Email: team@hivellm.org
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "vectorizer_sdk"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Python SDK for Vectorizer - Semantic search and vector operations with UMICP protocol support"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "HiveLLM Team", email = "team@hivellm.org"}
|
|
14
|
+
]
|
|
15
|
+
keywords = [
|
|
16
|
+
"vectorizer",
|
|
17
|
+
"semantic-search",
|
|
18
|
+
"embeddings",
|
|
19
|
+
"machine-learning",
|
|
20
|
+
"ai",
|
|
21
|
+
"search",
|
|
22
|
+
"vectors",
|
|
23
|
+
"similarity",
|
|
24
|
+
"hivellm",
|
|
25
|
+
"umicp"
|
|
26
|
+
]
|
|
27
|
+
classifiers = [
|
|
28
|
+
"Development Status :: 5 - Production/Stable",
|
|
29
|
+
"Intended Audience :: Developers",
|
|
30
|
+
"Operating System :: OS Independent",
|
|
31
|
+
"Programming Language :: Python :: 3",
|
|
32
|
+
"Programming Language :: Python :: 3.8",
|
|
33
|
+
"Programming Language :: Python :: 3.9",
|
|
34
|
+
"Programming Language :: Python :: 3.10",
|
|
35
|
+
"Programming Language :: Python :: 3.11",
|
|
36
|
+
"Programming Language :: Python :: 3.12",
|
|
37
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
38
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
39
|
+
"Topic :: Text Processing :: Indexing",
|
|
40
|
+
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
dependencies = [
|
|
44
|
+
"aiohttp>=3.8.0",
|
|
45
|
+
"umicp-sdk>=0.3.2",
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
[project.optional-dependencies]
|
|
49
|
+
dev = [
|
|
50
|
+
"pytest>=7.0.0",
|
|
51
|
+
"pytest-asyncio>=0.21.0",
|
|
52
|
+
"pytest-cov>=4.0.0",
|
|
53
|
+
"black>=23.0.0",
|
|
54
|
+
"isort>=5.12.0",
|
|
55
|
+
"flake8>=6.0.0",
|
|
56
|
+
"mypy>=1.0.0",
|
|
57
|
+
"pre-commit>=3.0.0",
|
|
58
|
+
]
|
|
59
|
+
docs = [
|
|
60
|
+
"sphinx>=6.0.0",
|
|
61
|
+
"sphinx-rtd-theme>=1.2.0",
|
|
62
|
+
"myst-parser>=1.0.0",
|
|
63
|
+
]
|
|
64
|
+
test = [
|
|
65
|
+
"pytest>=7.0.0",
|
|
66
|
+
"pytest-asyncio>=0.21.0",
|
|
67
|
+
"pytest-cov>=4.0.0",
|
|
68
|
+
"httpx>=0.24.0",
|
|
69
|
+
]
|
|
70
|
+
|
|
71
|
+
[project.urls]
|
|
72
|
+
Homepage = "https://github.com/hivellm/vectorizer"
|
|
73
|
+
Documentation = "https://github.com/hivellm/vectorizer/tree/main/docs"
|
|
74
|
+
Repository = "https://github.com/hivellm/vectorizer"
|
|
75
|
+
Issues = "https://github.com/hivellm/vectorizer/issues"
|
|
76
|
+
|
|
77
|
+
[project.scripts]
|
|
78
|
+
vectorizer-cli = "cli:main"
|
|
79
|
+
|
|
80
|
+
[tool.setuptools.packages.find]
|
|
81
|
+
include = ["*"]
|
|
82
|
+
exclude = ["tests*", "examples*", "docs*"]
|
|
83
|
+
|
|
84
|
+
[tool.setuptools.package-data]
|
|
85
|
+
"*" = ["py.typed"]
|
|
86
|
+
|
|
87
|
+
[tool.pytest.ini_options]
|
|
88
|
+
asyncio_mode = "auto"
|
|
89
|
+
testpaths = ["tests"]
|
|
90
|
+
python_files = ["test_*.py"]
|
|
91
|
+
python_classes = ["Test*"]
|
|
92
|
+
python_functions = ["test_*"]
|
|
93
|
+
|
|
94
|
+
[tool.black]
|
|
95
|
+
line-length = 100
|
|
96
|
+
target-version = ['py38', 'py39', 'py310', 'py311', 'py312']
|
|
97
|
+
|
|
98
|
+
[tool.isort]
|
|
99
|
+
profile = "black"
|
|
100
|
+
line_length = 100
|
|
101
|
+
|
|
102
|
+
[tool.mypy]
|
|
103
|
+
python_version = "3.8"
|
|
104
|
+
warn_return_any = true
|
|
105
|
+
warn_unused_configs = true
|
|
106
|
+
disallow_untyped_defs = false
|
|
107
|
+
|