llama-stack-api 0.4.3__py3-none-any.whl → 0.5.0rc1__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.
- llama_stack_api/__init__.py +1100 -0
- llama_stack_api/admin/__init__.py +45 -0
- llama_stack_api/admin/api.py +72 -0
- llama_stack_api/admin/fastapi_routes.py +117 -0
- llama_stack_api/admin/models.py +113 -0
- llama_stack_api/agents/__init__.py +38 -0
- llama_stack_api/agents/api.py +52 -0
- llama_stack_api/agents/fastapi_routes.py +268 -0
- llama_stack_api/agents/models.py +181 -0
- llama_stack_api/batches/__init__.py +40 -0
- llama_stack_api/batches/api.py +53 -0
- llama_stack_api/batches/fastapi_routes.py +113 -0
- llama_stack_api/batches/models.py +78 -0
- llama_stack_api/benchmarks/__init__.py +43 -0
- llama_stack_api/benchmarks/api.py +39 -0
- llama_stack_api/benchmarks/fastapi_routes.py +109 -0
- llama_stack_api/benchmarks/models.py +109 -0
- llama_stack_api/common/__init__.py +5 -0
- llama_stack_api/common/content_types.py +101 -0
- llama_stack_api/common/errors.py +110 -0
- llama_stack_api/common/job_types.py +38 -0
- llama_stack_api/common/responses.py +77 -0
- llama_stack_api/common/training_types.py +47 -0
- llama_stack_api/common/type_system.py +146 -0
- llama_stack_api/connectors/__init__.py +38 -0
- llama_stack_api/connectors/api.py +50 -0
- llama_stack_api/connectors/fastapi_routes.py +103 -0
- llama_stack_api/connectors/models.py +103 -0
- llama_stack_api/conversations/__init__.py +61 -0
- llama_stack_api/conversations/api.py +44 -0
- llama_stack_api/conversations/fastapi_routes.py +177 -0
- llama_stack_api/conversations/models.py +245 -0
- llama_stack_api/datasetio/__init__.py +34 -0
- llama_stack_api/datasetio/api.py +42 -0
- llama_stack_api/datasetio/fastapi_routes.py +94 -0
- llama_stack_api/datasetio/models.py +48 -0
- llama_stack_api/datasets/__init__.py +61 -0
- llama_stack_api/datasets/api.py +35 -0
- llama_stack_api/datasets/fastapi_routes.py +104 -0
- llama_stack_api/datasets/models.py +152 -0
- llama_stack_api/datatypes.py +373 -0
- llama_stack_api/eval/__init__.py +55 -0
- llama_stack_api/eval/api.py +51 -0
- llama_stack_api/eval/compat.py +300 -0
- llama_stack_api/eval/fastapi_routes.py +126 -0
- llama_stack_api/eval/models.py +141 -0
- llama_stack_api/file_processors/__init__.py +27 -0
- llama_stack_api/file_processors/api.py +64 -0
- llama_stack_api/file_processors/fastapi_routes.py +78 -0
- llama_stack_api/file_processors/models.py +42 -0
- llama_stack_api/files/__init__.py +35 -0
- llama_stack_api/files/api.py +51 -0
- llama_stack_api/files/fastapi_routes.py +124 -0
- llama_stack_api/files/models.py +107 -0
- llama_stack_api/inference/__init__.py +207 -0
- llama_stack_api/inference/api.py +93 -0
- llama_stack_api/inference/fastapi_routes.py +243 -0
- llama_stack_api/inference/models.py +1035 -0
- llama_stack_api/inspect_api/__init__.py +37 -0
- llama_stack_api/inspect_api/api.py +25 -0
- llama_stack_api/inspect_api/fastapi_routes.py +76 -0
- llama_stack_api/inspect_api/models.py +28 -0
- llama_stack_api/internal/__init__.py +9 -0
- llama_stack_api/internal/kvstore.py +28 -0
- llama_stack_api/internal/sqlstore.py +81 -0
- llama_stack_api/models/__init__.py +47 -0
- llama_stack_api/models/api.py +38 -0
- llama_stack_api/models/fastapi_routes.py +104 -0
- llama_stack_api/models/models.py +157 -0
- llama_stack_api/openai_responses.py +1494 -0
- llama_stack_api/post_training/__init__.py +73 -0
- llama_stack_api/post_training/api.py +36 -0
- llama_stack_api/post_training/fastapi_routes.py +116 -0
- llama_stack_api/post_training/models.py +339 -0
- llama_stack_api/prompts/__init__.py +47 -0
- llama_stack_api/prompts/api.py +44 -0
- llama_stack_api/prompts/fastapi_routes.py +163 -0
- llama_stack_api/prompts/models.py +177 -0
- llama_stack_api/providers/__init__.py +33 -0
- llama_stack_api/providers/api.py +16 -0
- llama_stack_api/providers/fastapi_routes.py +57 -0
- llama_stack_api/providers/models.py +24 -0
- llama_stack_api/rag_tool.py +168 -0
- llama_stack_api/resource.py +36 -0
- llama_stack_api/router_utils.py +160 -0
- llama_stack_api/safety/__init__.py +37 -0
- llama_stack_api/safety/api.py +29 -0
- llama_stack_api/safety/datatypes.py +83 -0
- llama_stack_api/safety/fastapi_routes.py +55 -0
- llama_stack_api/safety/models.py +38 -0
- llama_stack_api/schema_utils.py +251 -0
- llama_stack_api/scoring/__init__.py +66 -0
- llama_stack_api/scoring/api.py +35 -0
- llama_stack_api/scoring/fastapi_routes.py +67 -0
- llama_stack_api/scoring/models.py +81 -0
- llama_stack_api/scoring_functions/__init__.py +50 -0
- llama_stack_api/scoring_functions/api.py +39 -0
- llama_stack_api/scoring_functions/fastapi_routes.py +108 -0
- llama_stack_api/scoring_functions/models.py +214 -0
- llama_stack_api/shields/__init__.py +41 -0
- llama_stack_api/shields/api.py +39 -0
- llama_stack_api/shields/fastapi_routes.py +104 -0
- llama_stack_api/shields/models.py +74 -0
- llama_stack_api/tools.py +226 -0
- llama_stack_api/validators.py +46 -0
- llama_stack_api/vector_io/__init__.py +88 -0
- llama_stack_api/vector_io/api.py +234 -0
- llama_stack_api/vector_io/fastapi_routes.py +447 -0
- llama_stack_api/vector_io/models.py +663 -0
- llama_stack_api/vector_stores.py +53 -0
- llama_stack_api/version.py +9 -0
- {llama_stack_api-0.4.3.dist-info → llama_stack_api-0.5.0rc1.dist-info}/METADATA +1 -1
- llama_stack_api-0.5.0rc1.dist-info/RECORD +115 -0
- llama_stack_api-0.5.0rc1.dist-info/top_level.txt +1 -0
- llama_stack_api-0.4.3.dist-info/RECORD +0 -4
- llama_stack_api-0.4.3.dist-info/top_level.txt +0 -1
- {llama_stack_api-0.4.3.dist-info → llama_stack_api-0.5.0rc1.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,663 @@
|
|
|
1
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
# All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# This source code is licensed under the terms described in the LICENSE file in
|
|
5
|
+
# the root directory of this source tree.
|
|
6
|
+
|
|
7
|
+
"""Pydantic models for VectorIO API requests and responses.
|
|
8
|
+
|
|
9
|
+
This module defines the request and response models for the VectorIO API
|
|
10
|
+
using Pydantic with Field descriptions for OpenAPI schema generation.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from typing import Annotated, Any, Literal
|
|
14
|
+
|
|
15
|
+
from pydantic import BaseModel, Field, field_validator
|
|
16
|
+
|
|
17
|
+
from llama_stack_api.inference import InterleavedContent
|
|
18
|
+
from llama_stack_api.schema_utils import json_schema_type, register_schema
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@json_schema_type
|
|
22
|
+
class ChunkMetadata(BaseModel):
|
|
23
|
+
"""
|
|
24
|
+
`ChunkMetadata` is backend metadata for a `Chunk` that is used to store additional information about the chunk that
|
|
25
|
+
will not be used in the context during inference, but is required for backend functionality. The `ChunkMetadata`
|
|
26
|
+
is set during chunk creation in `MemoryToolRuntimeImpl().insert()`and is not expected to change after.
|
|
27
|
+
Use `Chunk.metadata` for metadata that will be used in the context during inference.
|
|
28
|
+
:param chunk_id: The ID of the chunk. If not set, it will be generated based on the document ID and content.
|
|
29
|
+
:param document_id: The ID of the document this chunk belongs to.
|
|
30
|
+
:param source: The source of the content, such as a URL, file path, or other identifier.
|
|
31
|
+
:param created_timestamp: An optional timestamp indicating when the chunk was created.
|
|
32
|
+
:param updated_timestamp: An optional timestamp indicating when the chunk was last updated.
|
|
33
|
+
:param chunk_window: The window of the chunk, which can be used to group related chunks together.
|
|
34
|
+
:param chunk_tokenizer: The tokenizer used to create the chunk. Default is Tiktoken.
|
|
35
|
+
:param content_token_count: The number of tokens in the content of the chunk.
|
|
36
|
+
:param metadata_token_count: The number of tokens in the metadata of the chunk.
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
chunk_id: str | None = None
|
|
40
|
+
document_id: str | None = None
|
|
41
|
+
source: str | None = None
|
|
42
|
+
created_timestamp: int | None = None
|
|
43
|
+
updated_timestamp: int | None = None
|
|
44
|
+
chunk_window: str | None = None
|
|
45
|
+
chunk_tokenizer: str | None = None
|
|
46
|
+
content_token_count: int | None = None
|
|
47
|
+
metadata_token_count: int | None = None
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@json_schema_type
|
|
51
|
+
class Chunk(BaseModel):
|
|
52
|
+
"""
|
|
53
|
+
A chunk of content from file processing.
|
|
54
|
+
:param content: The content of the chunk, which can be interleaved text, images, or other types.
|
|
55
|
+
:param chunk_id: Unique identifier for the chunk. Must be provided explicitly.
|
|
56
|
+
:param metadata: Metadata associated with the chunk that will be used in the model context during inference.
|
|
57
|
+
:param chunk_metadata: Metadata for the chunk that will NOT be used in the context during inference.
|
|
58
|
+
The `chunk_metadata` is required backend functionality.
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
content: InterleavedContent
|
|
62
|
+
chunk_id: str
|
|
63
|
+
metadata: dict[str, Any] = Field(default_factory=dict)
|
|
64
|
+
chunk_metadata: ChunkMetadata
|
|
65
|
+
|
|
66
|
+
@property
|
|
67
|
+
def document_id(self) -> str | None:
|
|
68
|
+
"""Returns the document_id from either metadata or chunk_metadata, with metadata taking precedence."""
|
|
69
|
+
# Check metadata first (takes precedence)
|
|
70
|
+
doc_id = self.metadata.get("document_id")
|
|
71
|
+
if doc_id is not None:
|
|
72
|
+
if not isinstance(doc_id, str):
|
|
73
|
+
raise TypeError(f"metadata['document_id'] must be a string, got {type(doc_id).__name__}: {doc_id!r}")
|
|
74
|
+
return doc_id
|
|
75
|
+
|
|
76
|
+
# Fall back to chunk_metadata if available (Pydantic ensures type safety)
|
|
77
|
+
if self.chunk_metadata is not None:
|
|
78
|
+
return self.chunk_metadata.document_id
|
|
79
|
+
|
|
80
|
+
return None
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@json_schema_type
|
|
84
|
+
class EmbeddedChunk(Chunk):
|
|
85
|
+
"""
|
|
86
|
+
A chunk of content with its embedding vector for vector database operations.
|
|
87
|
+
Inherits all fields from Chunk and adds embedding-related fields.
|
|
88
|
+
:param embedding: The embedding vector for the chunk content.
|
|
89
|
+
:param embedding_model: The model used to generate the embedding (e.g., 'openai/text-embedding-3-small').
|
|
90
|
+
:param embedding_dimension: The dimension of the embedding vector.
|
|
91
|
+
"""
|
|
92
|
+
|
|
93
|
+
embedding: list[float]
|
|
94
|
+
embedding_model: str
|
|
95
|
+
embedding_dimension: int
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
@json_schema_type
|
|
99
|
+
class QueryChunksResponse(BaseModel):
|
|
100
|
+
"""Response from querying chunks in a vector database.
|
|
101
|
+
|
|
102
|
+
:param chunks: List of embedded chunks returned from the query
|
|
103
|
+
:param scores: Relevance scores corresponding to each returned chunk
|
|
104
|
+
"""
|
|
105
|
+
|
|
106
|
+
chunks: list[EmbeddedChunk]
|
|
107
|
+
scores: list[float]
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
@json_schema_type
|
|
111
|
+
class VectorStoreFileCounts(BaseModel):
|
|
112
|
+
"""File processing status counts for a vector store.
|
|
113
|
+
|
|
114
|
+
:param completed: Number of files that have been successfully processed
|
|
115
|
+
:param cancelled: Number of files that had their processing cancelled
|
|
116
|
+
:param failed: Number of files that failed to process
|
|
117
|
+
:param in_progress: Number of files currently being processed
|
|
118
|
+
:param total: Total number of files in the vector store
|
|
119
|
+
"""
|
|
120
|
+
|
|
121
|
+
completed: int
|
|
122
|
+
cancelled: int
|
|
123
|
+
failed: int
|
|
124
|
+
in_progress: int
|
|
125
|
+
total: int
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
@json_schema_type
|
|
129
|
+
class VectorStoreObject(BaseModel):
|
|
130
|
+
"""OpenAI Vector Store object.
|
|
131
|
+
|
|
132
|
+
:param id: Unique identifier for the vector store
|
|
133
|
+
:param object: Object type identifier, always "vector_store"
|
|
134
|
+
:param created_at: Timestamp when the vector store was created
|
|
135
|
+
:param name: (Optional) Name of the vector store
|
|
136
|
+
:param usage_bytes: Storage space used by the vector store in bytes
|
|
137
|
+
:param file_counts: File processing status counts for the vector store
|
|
138
|
+
:param status: Current status of the vector store
|
|
139
|
+
:param expires_after: (Optional) Expiration policy for the vector store
|
|
140
|
+
:param expires_at: (Optional) Timestamp when the vector store will expire
|
|
141
|
+
:param last_active_at: (Optional) Timestamp of last activity on the vector store
|
|
142
|
+
:param metadata: Set of key-value pairs that can be attached to the vector store
|
|
143
|
+
"""
|
|
144
|
+
|
|
145
|
+
id: str
|
|
146
|
+
object: str = "vector_store"
|
|
147
|
+
created_at: int
|
|
148
|
+
name: str | None = None
|
|
149
|
+
usage_bytes: int = 0
|
|
150
|
+
file_counts: VectorStoreFileCounts
|
|
151
|
+
status: str = "completed"
|
|
152
|
+
expires_after: dict[str, Any] | None = None
|
|
153
|
+
expires_at: int | None = None
|
|
154
|
+
last_active_at: int | None = None
|
|
155
|
+
metadata: dict[str, Any] = Field(default_factory=dict)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
@json_schema_type
|
|
159
|
+
class VectorStoreCreateRequest(BaseModel):
|
|
160
|
+
"""Request to create a vector store.
|
|
161
|
+
|
|
162
|
+
:param name: (Optional) Name for the vector store
|
|
163
|
+
:param file_ids: List of file IDs to include in the vector store
|
|
164
|
+
:param expires_after: (Optional) Expiration policy for the vector store
|
|
165
|
+
:param chunking_strategy: (Optional) Strategy for splitting files into chunks
|
|
166
|
+
:param metadata: Set of key-value pairs that can be attached to the vector store
|
|
167
|
+
"""
|
|
168
|
+
|
|
169
|
+
name: str | None = None
|
|
170
|
+
file_ids: list[str] = Field(default_factory=list)
|
|
171
|
+
expires_after: dict[str, Any] | None = None
|
|
172
|
+
chunking_strategy: dict[str, Any] | None = None
|
|
173
|
+
metadata: dict[str, Any] = Field(default_factory=dict)
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
@json_schema_type
|
|
177
|
+
class VectorStoreModifyRequest(BaseModel):
|
|
178
|
+
"""Request to modify a vector store.
|
|
179
|
+
|
|
180
|
+
:param name: (Optional) Updated name for the vector store
|
|
181
|
+
:param expires_after: (Optional) Updated expiration policy for the vector store
|
|
182
|
+
:param metadata: (Optional) Updated set of key-value pairs for the vector store
|
|
183
|
+
"""
|
|
184
|
+
|
|
185
|
+
name: str | None = None
|
|
186
|
+
expires_after: dict[str, Any] | None = None
|
|
187
|
+
metadata: dict[str, Any] | None = None
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
@json_schema_type
|
|
191
|
+
class VectorStoreListResponse(BaseModel):
|
|
192
|
+
"""Response from listing vector stores.
|
|
193
|
+
|
|
194
|
+
:param object: Object type identifier, always "list"
|
|
195
|
+
:param data: List of vector store objects
|
|
196
|
+
:param first_id: (Optional) ID of the first vector store in the list for pagination
|
|
197
|
+
:param last_id: (Optional) ID of the last vector store in the list for pagination
|
|
198
|
+
:param has_more: Whether there are more vector stores available beyond this page
|
|
199
|
+
"""
|
|
200
|
+
|
|
201
|
+
object: str = "list"
|
|
202
|
+
data: list[VectorStoreObject]
|
|
203
|
+
first_id: str | None = None
|
|
204
|
+
last_id: str | None = None
|
|
205
|
+
has_more: bool = False
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
@json_schema_type
|
|
209
|
+
class VectorStoreSearchRequest(BaseModel):
|
|
210
|
+
"""Request to search a vector store.
|
|
211
|
+
|
|
212
|
+
:param query: Search query as a string or list of strings
|
|
213
|
+
:param filters: (Optional) Filters based on file attributes to narrow search results
|
|
214
|
+
:param max_num_results: Maximum number of results to return, defaults to 10
|
|
215
|
+
:param ranking_options: (Optional) Options for ranking and filtering search results
|
|
216
|
+
:param rewrite_query: Whether to rewrite the query for better vector search performance
|
|
217
|
+
"""
|
|
218
|
+
|
|
219
|
+
query: str | list[str]
|
|
220
|
+
filters: dict[str, Any] | None = None
|
|
221
|
+
max_num_results: int = 10
|
|
222
|
+
ranking_options: dict[str, Any] | None = None
|
|
223
|
+
rewrite_query: bool = False
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
@json_schema_type
|
|
227
|
+
class VectorStoreContent(BaseModel):
|
|
228
|
+
"""Content item from a vector store file or search result.
|
|
229
|
+
|
|
230
|
+
:param type: Content type, currently only "text" is supported
|
|
231
|
+
:param text: The actual text content
|
|
232
|
+
:param embedding: Optional embedding vector for this content chunk
|
|
233
|
+
:param chunk_metadata: Optional chunk metadata
|
|
234
|
+
:param metadata: Optional user-defined metadata
|
|
235
|
+
"""
|
|
236
|
+
|
|
237
|
+
type: Literal["text"]
|
|
238
|
+
text: str
|
|
239
|
+
embedding: list[float] | None = None
|
|
240
|
+
chunk_metadata: ChunkMetadata | None = None
|
|
241
|
+
metadata: dict[str, Any] | None = None
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
@json_schema_type
|
|
245
|
+
class VectorStoreSearchResponse(BaseModel):
|
|
246
|
+
"""Response from searching a vector store.
|
|
247
|
+
|
|
248
|
+
:param file_id: Unique identifier of the file containing the result
|
|
249
|
+
:param filename: Name of the file containing the result
|
|
250
|
+
:param score: Relevance score for this search result
|
|
251
|
+
:param attributes: (Optional) Key-value attributes associated with the file
|
|
252
|
+
:param content: List of content items matching the search query
|
|
253
|
+
"""
|
|
254
|
+
|
|
255
|
+
file_id: str
|
|
256
|
+
filename: str
|
|
257
|
+
score: float
|
|
258
|
+
attributes: dict[str, str | float | bool] | None = None
|
|
259
|
+
content: list[VectorStoreContent]
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
@json_schema_type
|
|
263
|
+
class VectorStoreSearchResponsePage(BaseModel):
|
|
264
|
+
"""Paginated response from searching a vector store.
|
|
265
|
+
|
|
266
|
+
:param object: Object type identifier for the search results page
|
|
267
|
+
:param search_query: The original search query that was executed
|
|
268
|
+
:param data: List of search result objects
|
|
269
|
+
:param has_more: Whether there are more results available beyond this page
|
|
270
|
+
:param next_page: (Optional) Token for retrieving the next page of results
|
|
271
|
+
"""
|
|
272
|
+
|
|
273
|
+
object: str = "vector_store.search_results.page"
|
|
274
|
+
search_query: list[str]
|
|
275
|
+
data: list[VectorStoreSearchResponse]
|
|
276
|
+
has_more: bool = False
|
|
277
|
+
next_page: str | None = None
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
@json_schema_type
|
|
281
|
+
class VectorStoreDeleteResponse(BaseModel):
|
|
282
|
+
"""Response from deleting a vector store.
|
|
283
|
+
|
|
284
|
+
:param id: Unique identifier of the deleted vector store
|
|
285
|
+
:param object: Object type identifier for the deletion response
|
|
286
|
+
:param deleted: Whether the deletion operation was successful
|
|
287
|
+
"""
|
|
288
|
+
|
|
289
|
+
id: str
|
|
290
|
+
object: str = "vector_store.deleted"
|
|
291
|
+
deleted: bool = True
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
@json_schema_type
|
|
295
|
+
class VectorStoreFileContentResponse(BaseModel):
|
|
296
|
+
"""Represents the parsed content of a vector store file.
|
|
297
|
+
|
|
298
|
+
:param object: The object type, which is always `vector_store.file_content.page`
|
|
299
|
+
:param data: Parsed content of the file
|
|
300
|
+
:param has_more: Indicates if there are more content pages to fetch
|
|
301
|
+
:param next_page: The token for the next page, if any
|
|
302
|
+
"""
|
|
303
|
+
|
|
304
|
+
object: Literal["vector_store.file_content.page"] = "vector_store.file_content.page"
|
|
305
|
+
data: list[VectorStoreContent]
|
|
306
|
+
has_more: bool = False
|
|
307
|
+
next_page: str | None = None
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
@json_schema_type
|
|
311
|
+
class VectorStoreChunkingStrategyAuto(BaseModel):
|
|
312
|
+
"""Automatic chunking strategy for vector store files.
|
|
313
|
+
|
|
314
|
+
:param type: Strategy type, always "auto" for automatic chunking
|
|
315
|
+
"""
|
|
316
|
+
|
|
317
|
+
type: Literal["auto"] = "auto"
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
@json_schema_type
|
|
321
|
+
class VectorStoreChunkingStrategyStaticConfig(BaseModel):
|
|
322
|
+
"""Configuration for static chunking strategy.
|
|
323
|
+
|
|
324
|
+
:param chunk_overlap_tokens: Number of tokens to overlap between adjacent chunks
|
|
325
|
+
:param max_chunk_size_tokens: Maximum number of tokens per chunk, must be between 100 and 4096
|
|
326
|
+
"""
|
|
327
|
+
|
|
328
|
+
chunk_overlap_tokens: int = 400
|
|
329
|
+
max_chunk_size_tokens: int = Field(800, ge=100, le=4096)
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
@json_schema_type
|
|
333
|
+
class VectorStoreChunkingStrategyStatic(BaseModel):
|
|
334
|
+
"""Static chunking strategy with configurable parameters.
|
|
335
|
+
|
|
336
|
+
:param type: Strategy type, always "static" for static chunking
|
|
337
|
+
:param static: Configuration parameters for the static chunking strategy
|
|
338
|
+
"""
|
|
339
|
+
|
|
340
|
+
type: Literal["static"] = "static"
|
|
341
|
+
static: VectorStoreChunkingStrategyStaticConfig
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
VectorStoreChunkingStrategy = Annotated[
|
|
345
|
+
VectorStoreChunkingStrategyAuto | VectorStoreChunkingStrategyStatic,
|
|
346
|
+
Field(discriminator="type"),
|
|
347
|
+
]
|
|
348
|
+
register_schema(VectorStoreChunkingStrategy, name="VectorStoreChunkingStrategy")
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
class SearchRankingOptions(BaseModel):
|
|
352
|
+
"""Options for ranking and filtering search results.
|
|
353
|
+
|
|
354
|
+
This class configures how search results are ranked and filtered. You can use algorithm-based
|
|
355
|
+
rerankers (weighted, RRF) or neural rerankers. Defaults from VectorStoresConfig are
|
|
356
|
+
used when parameters are not provided.
|
|
357
|
+
|
|
358
|
+
Examples:
|
|
359
|
+
# Weighted ranker with custom alpha
|
|
360
|
+
SearchRankingOptions(ranker="weighted", alpha=0.7)
|
|
361
|
+
|
|
362
|
+
# RRF ranker with custom impact factor
|
|
363
|
+
SearchRankingOptions(ranker="rrf", impact_factor=50.0)
|
|
364
|
+
|
|
365
|
+
# Use config defaults (just specify ranker type)
|
|
366
|
+
SearchRankingOptions(ranker="weighted") # Uses alpha from VectorStoresConfig
|
|
367
|
+
|
|
368
|
+
# Score threshold filtering
|
|
369
|
+
SearchRankingOptions(ranker="weighted", score_threshold=0.5)
|
|
370
|
+
|
|
371
|
+
:param ranker: (Optional) Name of the ranking algorithm to use. Supported values:
|
|
372
|
+
- "weighted": Weighted combination of vector and keyword scores
|
|
373
|
+
- "rrf": Reciprocal Rank Fusion algorithm
|
|
374
|
+
- "neural": Neural reranking model (requires model parameter, Part II)
|
|
375
|
+
Note: For OpenAI API compatibility, any string value is accepted, but only the above values are supported.
|
|
376
|
+
:param score_threshold: (Optional) Minimum relevance score threshold for results. Default: 0.0
|
|
377
|
+
:param alpha: (Optional) Weight factor for weighted ranker (0-1).
|
|
378
|
+
- 0.0 = keyword only
|
|
379
|
+
- 0.5 = equal weight (default)
|
|
380
|
+
- 1.0 = vector only
|
|
381
|
+
Only used when ranker="weighted" and weights is not provided.
|
|
382
|
+
Falls back to VectorStoresConfig.chunk_retrieval_params.weighted_search_alpha if not provided.
|
|
383
|
+
:param impact_factor: (Optional) Impact factor (k) for RRF algorithm.
|
|
384
|
+
Lower values emphasize higher-ranked results. Default: 60.0 (optimal from research).
|
|
385
|
+
Only used when ranker="rrf".
|
|
386
|
+
Falls back to VectorStoresConfig.chunk_retrieval_params.rrf_impact_factor if not provided.
|
|
387
|
+
:param weights: (Optional) Dictionary of weights for combining different signal types.
|
|
388
|
+
Keys can be "vector", "keyword", "neural". Values should sum to 1.0.
|
|
389
|
+
Used when combining algorithm-based reranking with neural reranking (Part II).
|
|
390
|
+
Example: {"vector": 0.3, "keyword": 0.3, "neural": 0.4}
|
|
391
|
+
:param model: (Optional) Model identifier for neural reranker (e.g., "vllm/Qwen3-Reranker-0.6B").
|
|
392
|
+
Required when ranker="neural" or when weights contains "neural" (Part II).
|
|
393
|
+
"""
|
|
394
|
+
|
|
395
|
+
ranker: str | None = None
|
|
396
|
+
# NOTE: OpenAI File Search Tool requires threshold to be between 0 and 1, however
|
|
397
|
+
# we don't guarantee that the score is between 0 and 1, so will leave this unconstrained
|
|
398
|
+
# and let the provider handle it
|
|
399
|
+
score_threshold: float | None = Field(default=0.0)
|
|
400
|
+
alpha: float | None = Field(default=None, ge=0.0, le=1.0, description="Weight factor for weighted ranker")
|
|
401
|
+
impact_factor: float | None = Field(default=None, gt=0.0, description="Impact factor for RRF algorithm")
|
|
402
|
+
weights: dict[str, float] | None = Field(
|
|
403
|
+
default=None,
|
|
404
|
+
description="Weights for combining vector, keyword, and neural scores. Keys: 'vector', 'keyword', 'neural'",
|
|
405
|
+
)
|
|
406
|
+
model: str | None = Field(default=None, description="Model identifier for neural reranker")
|
|
407
|
+
|
|
408
|
+
@field_validator("weights")
|
|
409
|
+
@classmethod
|
|
410
|
+
def validate_weights(cls, v: dict[str, float] | None) -> dict[str, float] | None:
|
|
411
|
+
if v is None:
|
|
412
|
+
return v
|
|
413
|
+
allowed_keys = {"vector", "keyword", "neural"}
|
|
414
|
+
if not all(key in allowed_keys for key in v.keys()):
|
|
415
|
+
raise ValueError(f"weights keys must be from {allowed_keys}")
|
|
416
|
+
if abs(sum(v.values()) - 1.0) > 0.001:
|
|
417
|
+
raise ValueError("weights must sum to 1.0")
|
|
418
|
+
return v
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
@json_schema_type
|
|
422
|
+
class VectorStoreFileLastError(BaseModel):
|
|
423
|
+
"""Error information for failed vector store file processing.
|
|
424
|
+
|
|
425
|
+
:param code: Error code indicating the type of failure
|
|
426
|
+
:param message: Human-readable error message describing the failure
|
|
427
|
+
"""
|
|
428
|
+
|
|
429
|
+
code: Literal["server_error"] | Literal["rate_limit_exceeded"]
|
|
430
|
+
message: str
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
VectorStoreFileStatus = Literal["completed"] | Literal["in_progress"] | Literal["cancelled"] | Literal["failed"]
|
|
434
|
+
register_schema(VectorStoreFileStatus, name="VectorStoreFileStatus")
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
# VectorStoreFileAttributes type with OpenAPI constraints
|
|
438
|
+
VectorStoreFileAttributes = Annotated[
|
|
439
|
+
dict[str, Annotated[str, Field(max_length=512)] | float | bool],
|
|
440
|
+
Field(
|
|
441
|
+
max_length=16,
|
|
442
|
+
json_schema_extra={
|
|
443
|
+
"propertyNames": {"type": "string", "maxLength": 64},
|
|
444
|
+
"x-oaiTypeLabel": "map",
|
|
445
|
+
},
|
|
446
|
+
description=(
|
|
447
|
+
"Set of 16 key-value pairs that can be attached to an object. This can be "
|
|
448
|
+
"useful for storing additional information about the object in a structured "
|
|
449
|
+
"format, and querying for objects via API or the dashboard. Keys are strings "
|
|
450
|
+
"with a maximum length of 64 characters. Values are strings with a maximum "
|
|
451
|
+
"length of 512 characters, booleans, or numbers."
|
|
452
|
+
),
|
|
453
|
+
),
|
|
454
|
+
]
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
def _sanitize_vector_store_attributes(metadata: dict[str, Any] | None) -> dict[str, str | float | bool]:
|
|
458
|
+
"""
|
|
459
|
+
Sanitize metadata to VectorStoreFileAttributes spec (max 16 properties, primitives only).
|
|
460
|
+
|
|
461
|
+
Converts dict[str, Any] to dict[str, str | float | bool]:
|
|
462
|
+
- Preserves: str (truncated to 512 chars), bool, int/float (as float)
|
|
463
|
+
- Converts: list -> comma-separated string
|
|
464
|
+
- Filters: dict, None, other types
|
|
465
|
+
- Enforces: max 16 properties, max 64 char keys, max 512 char string values
|
|
466
|
+
"""
|
|
467
|
+
if not metadata:
|
|
468
|
+
return {}
|
|
469
|
+
|
|
470
|
+
sanitized: dict[str, str | float | bool] = {}
|
|
471
|
+
for key, value in metadata.items():
|
|
472
|
+
# Enforce max 16 properties
|
|
473
|
+
if len(sanitized) >= 16:
|
|
474
|
+
break
|
|
475
|
+
|
|
476
|
+
# Enforce max 64 char keys
|
|
477
|
+
if len(key) > 64:
|
|
478
|
+
continue
|
|
479
|
+
|
|
480
|
+
# Convert to supported primitive types
|
|
481
|
+
if isinstance(value, bool):
|
|
482
|
+
sanitized[key] = value
|
|
483
|
+
elif isinstance(value, int | float):
|
|
484
|
+
sanitized[key] = float(value)
|
|
485
|
+
elif isinstance(value, str):
|
|
486
|
+
# Enforce max 512 char string values
|
|
487
|
+
sanitized[key] = value[:512] if len(value) > 512 else value
|
|
488
|
+
elif isinstance(value, list):
|
|
489
|
+
# Convert lists to comma-separated strings (max 512 chars)
|
|
490
|
+
list_str = ", ".join(str(item) for item in value)
|
|
491
|
+
sanitized[key] = list_str[:512] if len(list_str) > 512 else list_str
|
|
492
|
+
|
|
493
|
+
return sanitized
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
@json_schema_type
|
|
497
|
+
class VectorStoreFileObject(BaseModel):
|
|
498
|
+
"""OpenAI Vector Store File object.
|
|
499
|
+
|
|
500
|
+
:param id: Unique identifier for the file
|
|
501
|
+
:param object: Object type identifier, always "vector_store.file"
|
|
502
|
+
:param attributes: Key-value attributes associated with the file
|
|
503
|
+
:param chunking_strategy: Strategy used for splitting the file into chunks
|
|
504
|
+
:param created_at: Timestamp when the file was added to the vector store
|
|
505
|
+
:param last_error: (Optional) Error information if file processing failed
|
|
506
|
+
:param status: Current processing status of the file
|
|
507
|
+
:param usage_bytes: Storage space used by this file in bytes
|
|
508
|
+
:param vector_store_id: ID of the vector store containing this file
|
|
509
|
+
"""
|
|
510
|
+
|
|
511
|
+
id: str
|
|
512
|
+
object: str = "vector_store.file"
|
|
513
|
+
attributes: VectorStoreFileAttributes = Field(default_factory=dict)
|
|
514
|
+
chunking_strategy: VectorStoreChunkingStrategy
|
|
515
|
+
created_at: int
|
|
516
|
+
last_error: VectorStoreFileLastError | None = None
|
|
517
|
+
status: VectorStoreFileStatus
|
|
518
|
+
usage_bytes: int = 0
|
|
519
|
+
vector_store_id: str
|
|
520
|
+
|
|
521
|
+
@field_validator("attributes", mode="before")
|
|
522
|
+
@classmethod
|
|
523
|
+
def _validate_attributes(cls, v: dict[str, Any] | None) -> dict[str, str | float | bool]:
|
|
524
|
+
"""Sanitize attributes to match VectorStoreFileAttributes OpenAPI spec."""
|
|
525
|
+
return _sanitize_vector_store_attributes(v)
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
@json_schema_type
|
|
529
|
+
class VectorStoreListFilesResponse(BaseModel):
|
|
530
|
+
"""Response from listing files in a vector store.
|
|
531
|
+
|
|
532
|
+
:param object: Object type identifier, always "list"
|
|
533
|
+
:param data: List of vector store file objects
|
|
534
|
+
:param first_id: (Optional) ID of the first file in the list for pagination
|
|
535
|
+
:param last_id: (Optional) ID of the last file in the list for pagination
|
|
536
|
+
:param has_more: Whether there are more files available beyond this page
|
|
537
|
+
"""
|
|
538
|
+
|
|
539
|
+
object: str = "list"
|
|
540
|
+
data: list[VectorStoreFileObject]
|
|
541
|
+
first_id: str | None = None
|
|
542
|
+
last_id: str | None = None
|
|
543
|
+
has_more: bool = False
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
@json_schema_type
|
|
547
|
+
class VectorStoreFileDeleteResponse(BaseModel):
|
|
548
|
+
"""Response from deleting a vector store file.
|
|
549
|
+
|
|
550
|
+
:param id: Unique identifier of the deleted file
|
|
551
|
+
:param object: Object type identifier for the deletion response
|
|
552
|
+
:param deleted: Whether the deletion operation was successful
|
|
553
|
+
"""
|
|
554
|
+
|
|
555
|
+
id: str
|
|
556
|
+
object: str = "vector_store.file.deleted"
|
|
557
|
+
deleted: bool = True
|
|
558
|
+
|
|
559
|
+
|
|
560
|
+
@json_schema_type
|
|
561
|
+
class VectorStoreFileBatchObject(BaseModel):
|
|
562
|
+
"""OpenAI Vector Store File Batch object.
|
|
563
|
+
|
|
564
|
+
:param id: Unique identifier for the file batch
|
|
565
|
+
:param object: Object type identifier, always "vector_store.file_batch"
|
|
566
|
+
:param created_at: Timestamp when the file batch was created
|
|
567
|
+
:param vector_store_id: ID of the vector store containing the file batch
|
|
568
|
+
:param status: Current processing status of the file batch
|
|
569
|
+
:param file_counts: File processing status counts for the batch
|
|
570
|
+
"""
|
|
571
|
+
|
|
572
|
+
id: str
|
|
573
|
+
object: str = "vector_store.file_batch"
|
|
574
|
+
created_at: int
|
|
575
|
+
vector_store_id: str
|
|
576
|
+
status: VectorStoreFileStatus
|
|
577
|
+
file_counts: VectorStoreFileCounts
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
@json_schema_type
|
|
581
|
+
class VectorStoreFilesListInBatchResponse(BaseModel):
|
|
582
|
+
"""Response from listing files in a vector store file batch.
|
|
583
|
+
|
|
584
|
+
:param object: Object type identifier, always "list"
|
|
585
|
+
:param data: List of vector store file objects in the batch
|
|
586
|
+
:param first_id: (Optional) ID of the first file in the list for pagination
|
|
587
|
+
:param last_id: (Optional) ID of the last file in the list for pagination
|
|
588
|
+
:param has_more: Whether there are more files available beyond this page
|
|
589
|
+
"""
|
|
590
|
+
|
|
591
|
+
object: str = "list"
|
|
592
|
+
data: list[VectorStoreFileObject]
|
|
593
|
+
first_id: str | None = None
|
|
594
|
+
last_id: str | None = None
|
|
595
|
+
has_more: bool = False
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
# extra_body can be accessed via .model_extra
|
|
599
|
+
@json_schema_type
|
|
600
|
+
class OpenAICreateVectorStoreRequestWithExtraBody(BaseModel, extra="allow"):
|
|
601
|
+
"""Request to create a vector store with extra_body support.
|
|
602
|
+
|
|
603
|
+
:param name: (Optional) A name for the vector store
|
|
604
|
+
:param file_ids: List of file IDs to include in the vector store
|
|
605
|
+
:param expires_after: (Optional) Expiration policy for the vector store
|
|
606
|
+
:param chunking_strategy: (Optional) Strategy for splitting files into chunks
|
|
607
|
+
:param metadata: Set of key-value pairs that can be attached to the vector store
|
|
608
|
+
"""
|
|
609
|
+
|
|
610
|
+
name: str | None = None
|
|
611
|
+
file_ids: list[str] | None = None
|
|
612
|
+
expires_after: dict[str, Any] | None = None
|
|
613
|
+
chunking_strategy: VectorStoreChunkingStrategy | None = None
|
|
614
|
+
metadata: dict[str, Any] | None = None
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
# extra_body can be accessed via .model_extra
|
|
618
|
+
@json_schema_type
|
|
619
|
+
class OpenAICreateVectorStoreFileBatchRequestWithExtraBody(BaseModel, extra="allow"):
|
|
620
|
+
"""Request to create a vector store file batch with extra_body support.
|
|
621
|
+
|
|
622
|
+
:param file_ids: A list of File IDs that the vector store should use
|
|
623
|
+
:param attributes: (Optional) Key-value attributes to store with the files
|
|
624
|
+
:param chunking_strategy: (Optional) The chunking strategy used to chunk the file(s). Defaults to auto
|
|
625
|
+
"""
|
|
626
|
+
|
|
627
|
+
file_ids: list[str]
|
|
628
|
+
attributes: dict[str, Any] | None = None
|
|
629
|
+
chunking_strategy: VectorStoreChunkingStrategy | None = None
|
|
630
|
+
|
|
631
|
+
|
|
632
|
+
__all__ = [
|
|
633
|
+
"Chunk",
|
|
634
|
+
"ChunkMetadata",
|
|
635
|
+
"EmbeddedChunk",
|
|
636
|
+
"OpenAICreateVectorStoreFileBatchRequestWithExtraBody",
|
|
637
|
+
"OpenAICreateVectorStoreRequestWithExtraBody",
|
|
638
|
+
"QueryChunksResponse",
|
|
639
|
+
"SearchRankingOptions",
|
|
640
|
+
"VectorStoreChunkingStrategy",
|
|
641
|
+
"VectorStoreChunkingStrategyAuto",
|
|
642
|
+
"VectorStoreChunkingStrategyStatic",
|
|
643
|
+
"VectorStoreChunkingStrategyStaticConfig",
|
|
644
|
+
"VectorStoreContent",
|
|
645
|
+
"VectorStoreCreateRequest",
|
|
646
|
+
"VectorStoreDeleteResponse",
|
|
647
|
+
"VectorStoreFileAttributes",
|
|
648
|
+
"VectorStoreFileBatchObject",
|
|
649
|
+
"VectorStoreFileContentResponse",
|
|
650
|
+
"VectorStoreFileCounts",
|
|
651
|
+
"VectorStoreFileDeleteResponse",
|
|
652
|
+
"VectorStoreFileLastError",
|
|
653
|
+
"VectorStoreFileObject",
|
|
654
|
+
"VectorStoreFileStatus",
|
|
655
|
+
"VectorStoreFilesListInBatchResponse",
|
|
656
|
+
"VectorStoreListFilesResponse",
|
|
657
|
+
"VectorStoreListResponse",
|
|
658
|
+
"VectorStoreModifyRequest",
|
|
659
|
+
"VectorStoreObject",
|
|
660
|
+
"VectorStoreSearchRequest",
|
|
661
|
+
"VectorStoreSearchResponse",
|
|
662
|
+
"VectorStoreSearchResponsePage",
|
|
663
|
+
]
|