hammad-python 0.0.10__py3-none-any.whl → 0.0.11__py3-none-any.whl
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.
- hammad/__init__.py +64 -10
- hammad/based/__init__.py +52 -0
- hammad/based/fields.py +546 -0
- hammad/based/model.py +968 -0
- hammad/based/utils.py +455 -0
- hammad/cache/__init__.py +30 -0
- hammad/{cache.py → cache/_cache.py} +83 -12
- hammad/cli/__init__.py +25 -0
- hammad/cli/plugins/__init__.py +786 -0
- hammad/cli/styles/__init__.py +5 -0
- hammad/cli/styles/animations.py +548 -0
- hammad/cli/styles/settings.py +135 -0
- hammad/cli/styles/types.py +358 -0
- hammad/cli/styles/utils.py +480 -0
- hammad/data/__init__.py +51 -0
- hammad/data/collections/__init__.py +32 -0
- hammad/data/collections/base_collection.py +58 -0
- hammad/data/collections/collection.py +227 -0
- hammad/data/collections/searchable_collection.py +556 -0
- hammad/data/collections/vector_collection.py +497 -0
- hammad/data/databases/__init__.py +21 -0
- hammad/data/databases/database.py +551 -0
- hammad/data/types/__init__.py +33 -0
- hammad/data/types/files/__init__.py +1 -0
- hammad/data/types/files/audio.py +81 -0
- hammad/data/types/files/configuration.py +475 -0
- hammad/data/types/files/document.py +195 -0
- hammad/data/types/files/file.py +358 -0
- hammad/data/types/files/image.py +80 -0
- hammad/json/__init__.py +21 -0
- hammad/{utils/json → json}/converters.py +4 -1
- hammad/logging/__init__.py +27 -0
- hammad/logging/decorators.py +432 -0
- hammad/logging/logger.py +534 -0
- hammad/pydantic/__init__.py +43 -0
- hammad/{utils/pydantic → pydantic}/converters.py +2 -1
- hammad/pydantic/models/__init__.py +28 -0
- hammad/pydantic/models/arbitrary_model.py +46 -0
- hammad/pydantic/models/cacheable_model.py +79 -0
- hammad/pydantic/models/fast_model.py +318 -0
- hammad/pydantic/models/function_model.py +176 -0
- hammad/pydantic/models/subscriptable_model.py +63 -0
- hammad/text/__init__.py +37 -0
- hammad/text/text.py +1068 -0
- hammad/text/utils/__init__.py +1 -0
- hammad/{utils/text → text/utils}/converters.py +2 -2
- hammad/text/utils/markdown/__init__.py +1 -0
- hammad/{utils → text/utils}/markdown/converters.py +3 -3
- hammad/{utils → text/utils}/markdown/formatting.py +1 -1
- hammad/{utils/typing/utils.py → typing/__init__.py} +75 -2
- hammad/web/__init__.py +42 -0
- hammad/web/http/__init__.py +1 -0
- hammad/web/http/client.py +944 -0
- hammad/web/openapi/client.py +740 -0
- hammad/web/search/__init__.py +1 -0
- hammad/web/search/client.py +936 -0
- hammad/web/utils.py +463 -0
- hammad/yaml/__init__.py +30 -0
- hammad/yaml/converters.py +19 -0
- {hammad_python-0.0.10.dist-info → hammad_python-0.0.11.dist-info}/METADATA +14 -8
- hammad_python-0.0.11.dist-info/RECORD +65 -0
- hammad/database.py +0 -447
- hammad/logger.py +0 -273
- hammad/types/color.py +0 -951
- hammad/utils/json/__init__.py +0 -0
- hammad/utils/markdown/__init__.py +0 -0
- hammad/utils/pydantic/__init__.py +0 -0
- hammad/utils/text/__init__.py +0 -0
- hammad/utils/typing/__init__.py +0 -0
- hammad_python-0.0.10.dist-info/RECORD +0 -22
- /hammad/{types/__init__.py → py.typed} +0 -0
- /hammad/{utils → web/openapi}/__init__.py +0 -0
- {hammad_python-0.0.10.dist-info → hammad_python-0.0.11.dist-info}/WHEEL +0 -0
- {hammad_python-0.0.10.dist-info → hammad_python-0.0.11.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,227 @@
|
|
1
|
+
"""hammad.data.collections.collection"""
|
2
|
+
|
3
|
+
from typing import (
|
4
|
+
TYPE_CHECKING,
|
5
|
+
Literal,
|
6
|
+
Optional,
|
7
|
+
overload,
|
8
|
+
Any,
|
9
|
+
List,
|
10
|
+
Callable,
|
11
|
+
Union,
|
12
|
+
)
|
13
|
+
from typing_extensions import TypedDict
|
14
|
+
|
15
|
+
if TYPE_CHECKING:
|
16
|
+
from .searchable_collection import SearchableCollection
|
17
|
+
from .vector_collection import VectorCollection
|
18
|
+
|
19
|
+
|
20
|
+
Distance = Literal[
|
21
|
+
"cosine",
|
22
|
+
"euclidean",
|
23
|
+
"manhattan",
|
24
|
+
"hamming",
|
25
|
+
"dot",
|
26
|
+
"l2",
|
27
|
+
"l1",
|
28
|
+
"l2_squared",
|
29
|
+
"l1_squared",
|
30
|
+
"cosine_sim",
|
31
|
+
"euclidean_sim",
|
32
|
+
"manhattan_sim",
|
33
|
+
"hamming_sim",
|
34
|
+
"dot_sim",
|
35
|
+
]
|
36
|
+
|
37
|
+
|
38
|
+
class SearchableCollectionSettings(TypedDict, total=False):
|
39
|
+
"""Configuration settings for SearchableCollection using tantivy."""
|
40
|
+
|
41
|
+
heap_size: int
|
42
|
+
num_threads: Optional[int]
|
43
|
+
index_path: Optional[str]
|
44
|
+
schema_builder: Optional[Any]
|
45
|
+
writer_memory: Optional[int]
|
46
|
+
reload_policy: Optional[str]
|
47
|
+
|
48
|
+
|
49
|
+
class VectorCollectionSettings(TypedDict, total=False):
|
50
|
+
"""Configuration settings for VectorCollection using Qdrant."""
|
51
|
+
|
52
|
+
path: Optional[str]
|
53
|
+
host: Optional[str]
|
54
|
+
port: Optional[int]
|
55
|
+
grpc_port: Optional[int]
|
56
|
+
prefer_grpc: Optional[bool]
|
57
|
+
api_key: Optional[str]
|
58
|
+
timeout: Optional[float]
|
59
|
+
|
60
|
+
|
61
|
+
@overload
|
62
|
+
def create_collection(
|
63
|
+
type: Literal["searchable"],
|
64
|
+
name: str,
|
65
|
+
*,
|
66
|
+
schema: Optional[Any] = None,
|
67
|
+
default_ttl: Optional[int] = None,
|
68
|
+
storage_backend: Optional[Any] = None,
|
69
|
+
heap_size: Optional[int] = None,
|
70
|
+
num_threads: Optional[int] = None,
|
71
|
+
index_path: Optional[str] = None,
|
72
|
+
schema_builder: Optional[Any] = None,
|
73
|
+
writer_memory: Optional[int] = None,
|
74
|
+
reload_policy: Optional[str] = None,
|
75
|
+
) -> "SearchableCollection": ...
|
76
|
+
|
77
|
+
|
78
|
+
@overload
|
79
|
+
def create_collection(
|
80
|
+
type: Literal["vector"],
|
81
|
+
name: str,
|
82
|
+
vector_size: int,
|
83
|
+
*,
|
84
|
+
schema: Optional[Any] = None,
|
85
|
+
default_ttl: Optional[int] = None,
|
86
|
+
storage_backend: Optional[Any] = None,
|
87
|
+
distance_metric: Optional[Any] = None,
|
88
|
+
embedding_function: Optional[Callable[[Any], List[float]]] = None,
|
89
|
+
path: Optional[str] = None,
|
90
|
+
host: Optional[str] = None,
|
91
|
+
port: Optional[int] = None,
|
92
|
+
grpc_port: Optional[int] = None,
|
93
|
+
prefer_grpc: Optional[bool] = None,
|
94
|
+
api_key: Optional[str] = None,
|
95
|
+
timeout: Optional[float] = None,
|
96
|
+
) -> "VectorCollection": ...
|
97
|
+
|
98
|
+
|
99
|
+
def create_collection(
|
100
|
+
type: Literal["searchable", "vector"],
|
101
|
+
name: str,
|
102
|
+
vector_size: Optional[int] = None,
|
103
|
+
*,
|
104
|
+
schema: Optional[Any] = None,
|
105
|
+
default_ttl: Optional[int] = None,
|
106
|
+
storage_backend: Optional[Any] = None,
|
107
|
+
distance_metric: Optional[Any] = None,
|
108
|
+
embedding_function: Optional[Callable[[Any], List[float]]] = None,
|
109
|
+
# Tantivy parameters (searchable collections only)
|
110
|
+
heap_size: Optional[int] = None,
|
111
|
+
num_threads: Optional[int] = None,
|
112
|
+
index_path: Optional[str] = None,
|
113
|
+
schema_builder: Optional[Any] = None,
|
114
|
+
writer_memory: Optional[int] = None,
|
115
|
+
reload_policy: Optional[str] = None,
|
116
|
+
# Qdrant parameters (vector collections only)
|
117
|
+
path: Optional[str] = None,
|
118
|
+
host: Optional[str] = None,
|
119
|
+
port: Optional[int] = None,
|
120
|
+
grpc_port: Optional[int] = None,
|
121
|
+
prefer_grpc: Optional[bool] = None,
|
122
|
+
api_key: Optional[str] = None,
|
123
|
+
timeout: Optional[float] = None,
|
124
|
+
) -> Union["SearchableCollection", "VectorCollection"]:
|
125
|
+
"""
|
126
|
+
Create a collection of the specified type.
|
127
|
+
|
128
|
+
Args:
|
129
|
+
type: Type of collection to create ("searchable" or "vector")
|
130
|
+
name: Name of the collection
|
131
|
+
vector_size: Size of vectors (required for vector collections)
|
132
|
+
schema: Optional schema for type validation
|
133
|
+
default_ttl: Default TTL for items in seconds
|
134
|
+
storage_backend: Optional storage backend
|
135
|
+
distance_metric: Distance metric for similarity search (vector collections only)
|
136
|
+
embedding_function: Function to convert objects to vectors (vector collections only)
|
137
|
+
|
138
|
+
Tantivy parameters (searchable collections only):
|
139
|
+
heap_size: Memory allocation for tantivy heap
|
140
|
+
num_threads: Number of threads for tantivy operations
|
141
|
+
index_path: Path to store tantivy index files
|
142
|
+
schema_builder: Custom schema builder for tantivy
|
143
|
+
writer_memory: Memory allocation for tantivy writer
|
144
|
+
reload_policy: Policy for reloading tantivy index
|
145
|
+
|
146
|
+
Qdrant parameters (vector collections only):
|
147
|
+
path: Path for local Qdrant storage
|
148
|
+
host: Qdrant server host
|
149
|
+
port: Qdrant server port
|
150
|
+
grpc_port: Qdrant gRPC port
|
151
|
+
prefer_grpc: Whether to prefer gRPC over HTTP
|
152
|
+
api_key: API key for Qdrant authentication
|
153
|
+
timeout: Request timeout for Qdrant operations
|
154
|
+
|
155
|
+
Returns:
|
156
|
+
A SearchableCollection or VectorCollection instance
|
157
|
+
"""
|
158
|
+
if type == "searchable":
|
159
|
+
from .searchable_collection import SearchableCollection
|
160
|
+
|
161
|
+
# Build tantivy config from individual parameters
|
162
|
+
tantivy_config = {}
|
163
|
+
if heap_size is not None:
|
164
|
+
tantivy_config["heap_size"] = heap_size
|
165
|
+
if num_threads is not None:
|
166
|
+
tantivy_config["num_threads"] = num_threads
|
167
|
+
if index_path is not None:
|
168
|
+
tantivy_config["index_path"] = index_path
|
169
|
+
if schema_builder is not None:
|
170
|
+
tantivy_config["schema_builder"] = schema_builder
|
171
|
+
if writer_memory is not None:
|
172
|
+
tantivy_config["writer_memory"] = writer_memory
|
173
|
+
if reload_policy is not None:
|
174
|
+
tantivy_config["reload_policy"] = reload_policy
|
175
|
+
|
176
|
+
return SearchableCollection(
|
177
|
+
name=name,
|
178
|
+
schema=schema,
|
179
|
+
default_ttl=default_ttl,
|
180
|
+
storage_backend=storage_backend,
|
181
|
+
tantivy_config=tantivy_config if tantivy_config else None,
|
182
|
+
)
|
183
|
+
elif type == "vector":
|
184
|
+
if vector_size is None:
|
185
|
+
raise ValueError("vector_size is required for vector collections")
|
186
|
+
|
187
|
+
try:
|
188
|
+
from .vector_collection import VectorCollection, Distance
|
189
|
+
except ImportError:
|
190
|
+
raise ImportError(
|
191
|
+
"qdrant-client is required for vector collections. "
|
192
|
+
"Please install it with 'pip install qdrant-client'."
|
193
|
+
)
|
194
|
+
|
195
|
+
# Set default distance metric if not provided and Distance is available
|
196
|
+
if distance_metric is None and Distance is not None:
|
197
|
+
distance_metric = Distance.DOT
|
198
|
+
|
199
|
+
# Build qdrant config from individual parameters
|
200
|
+
qdrant_config = {}
|
201
|
+
if path is not None:
|
202
|
+
qdrant_config["path"] = path
|
203
|
+
if host is not None:
|
204
|
+
qdrant_config["host"] = host
|
205
|
+
if port is not None:
|
206
|
+
qdrant_config["port"] = port
|
207
|
+
if grpc_port is not None:
|
208
|
+
qdrant_config["grpc_port"] = grpc_port
|
209
|
+
if prefer_grpc is not None:
|
210
|
+
qdrant_config["prefer_grpc"] = prefer_grpc
|
211
|
+
if api_key is not None:
|
212
|
+
qdrant_config["api_key"] = api_key
|
213
|
+
if timeout is not None:
|
214
|
+
qdrant_config["timeout"] = timeout
|
215
|
+
|
216
|
+
return VectorCollection(
|
217
|
+
name=name,
|
218
|
+
vector_size=vector_size,
|
219
|
+
schema=schema,
|
220
|
+
default_ttl=default_ttl,
|
221
|
+
storage_backend=storage_backend,
|
222
|
+
distance_metric=distance_metric,
|
223
|
+
qdrant_config=qdrant_config if qdrant_config else None,
|
224
|
+
embedding_function=embedding_function,
|
225
|
+
)
|
226
|
+
else:
|
227
|
+
raise ValueError(f"Unsupported collection type: {type}")
|