Vector Stores
List vector stores
vector_stores.list(VectorStoreListParams**kwargs) -> SyncCursorPage[VectorStore]
get /vector_stores
Returns a list of vector stores.
Parameters
-
after: Optional[str]A cursor for use in pagination.
afteris an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. -
before: Optional[str]A cursor for use in pagination.
beforeis an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. -
limit: Optional[int]A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.
-
order: Optional[Literal["asc", "desc"]]Sort order by the
created_attimestamp of the objects.ascfor ascending order anddescfor descending order.-
"asc" -
"desc"
-
Returns
-
class VectorStore: …A vector store is a collection of processed files can be used by the
file_searchtool.-
id: strThe identifier, which can be referenced in API endpoints.
-
created_at: intThe Unix timestamp (in seconds) for when the vector store was created.
-
file_counts: FileCounts-
cancelled: intThe number of files that were cancelled.
-
completed: intThe number of files that have been successfully processed.
-
failed: intThe number of files that have failed to process.
-
in_progress: intThe number of files that are currently being processed.
-
total: intThe total number of files.
-
-
last_active_at: Optional[int]The Unix timestamp (in seconds) for when the vector store was last active.
-
metadata: Optional[Metadata]Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard.
Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.
-
name: strThe name of the vector store.
-
object: Literal["vector_store"]The object type, which is always
vector_store."vector_store"
-
status: Literal["expired", "in_progress", "completed"]The status of the vector store, which can be either
expired,in_progress, orcompleted. A status ofcompletedindicates that the vector store is ready for use.-
"expired" -
"in_progress" -
"completed"
-
-
usage_bytes: intThe total number of bytes used by the files in the vector store.
-
expires_after: Optional[ExpiresAfter]The expiration policy for a vector store.
-
anchor: Literal["last_active_at"]Anchor timestamp after which the expiration policy applies. Supported anchors:
last_active_at."last_active_at"
-
days: intThe number of days after the anchor time that the vector store will expire.
-
-
expires_at: Optional[int]The Unix timestamp (in seconds) for when the vector store will expire.
-
Example
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
)
page = client.vector_stores.list()
page = page.data[0]
print(page.id)
Response
{
"data": [
{
"id": "id",
"created_at": 0,
"file_counts": {
"cancelled": 0,
"completed": 0,
"failed": 0,
"in_progress": 0,
"total": 0
},
"last_active_at": 0,
"metadata": {
"foo": "string"
},
"name": "name",
"object": "vector_store",
"status": "expired",
"usage_bytes": 0,
"expires_after": {
"anchor": "last_active_at",
"days": 1
},
"expires_at": 0
}
],
"first_id": "vs_abc123",
"has_more": false,
"last_id": "vs_abc456",
"object": "list"
}
Example
from openai import OpenAI
client = OpenAI()
vector_stores = client.vector_stores.list()
print(vector_stores)
Response
{
"object": "list",
"data": [
{
"id": "vs_abc123",
"object": "vector_store",
"created_at": 1699061776,
"name": "Support FAQ",
"description": "Contains commonly asked questions and answers, organized by topic.",
"bytes": 139920,
"file_counts": {
"in_progress": 0,
"completed": 3,
"failed": 0,
"cancelled": 0,
"total": 3
}
},
{
"id": "vs_abc456",
"object": "vector_store",
"created_at": 1699061776,
"name": "Support FAQ v2",
"description": null,
"bytes": 139920,
"file_counts": {
"in_progress": 0,
"completed": 3,
"failed": 0,
"cancelled": 0,
"total": 3
}
}
],
"first_id": "vs_abc123",
"last_id": "vs_abc456",
"has_more": false
}
Create vector store
vector_stores.create(VectorStoreCreateParams**kwargs) -> VectorStore
post /vector_stores
Create a vector store.
Parameters
-
chunking_strategy: Optional[FileChunkingStrategyParam]The chunking strategy used to chunk the file(s). If not set, will use the
autostrategy. Only applicable iffile_idsis non-empty.-
class AutoFileChunkingStrategyParam: …The default strategy. This strategy currently uses a
max_chunk_size_tokensof800andchunk_overlap_tokensof400.-
type: Literal["auto"]Always
auto."auto"
-
-
class StaticFileChunkingStrategyObjectParam: …Customize your own chunking strategy by setting chunk size and chunk overlap.
-
static: StaticFileChunkingStrategy-
chunk_overlap_tokens: intThe number of tokens that overlap between chunks. The default value is
400.Note that the overlap must not exceed half of
max_chunk_size_tokens. -
max_chunk_size_tokens: intThe maximum number of tokens in each chunk. The default value is
800. The minimum value is100and the maximum value is4096.
-
-
type: Literal["static"]Always
static."static"
-
-
-
description: Optional[str]A description for the vector store. Can be used to describe the vector store's purpose.
-
expires_after: Optional[ExpiresAfter]The expiration policy for a vector store.
-
anchor: Literal["last_active_at"]Anchor timestamp after which the expiration policy applies. Supported anchors:
last_active_at."last_active_at"
-
days: intThe number of days after the anchor time that the vector store will expire.
-
-
file_ids: Optional[Sequence[str]]A list of File IDs that the vector store should use. Useful for tools like
file_searchthat can access files. -
metadata: Optional[Metadata]Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard.
Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.
-
name: Optional[str]The name of the vector store.
Returns
-
class VectorStore: …A vector store is a collection of processed files can be used by the
file_searchtool.-
id: strThe identifier, which can be referenced in API endpoints.
-
created_at: intThe Unix timestamp (in seconds) for when the vector store was created.
-
file_counts: FileCounts-
cancelled: intThe number of files that were cancelled.
-
completed: intThe number of files that have been successfully processed.
-
failed: intThe number of files that have failed to process.
-
in_progress: intThe number of files that are currently being processed.
-
total: intThe total number of files.
-
-
last_active_at: Optional[int]The Unix timestamp (in seconds) for when the vector store was last active.
-
metadata: Optional[Metadata]Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard.
Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.
-
name: strThe name of the vector store.
-
object: Literal["vector_store"]The object type, which is always
vector_store."vector_store"
-
status: Literal["expired", "in_progress", "completed"]The status of the vector store, which can be either
expired,in_progress, orcompleted. A status ofcompletedindicates that the vector store is ready for use.-
"expired" -
"in_progress" -
"completed"
-
-
usage_bytes: intThe total number of bytes used by the files in the vector store.
-
expires_after: Optional[ExpiresAfter]The expiration policy for a vector store.
-
anchor: Literal["last_active_at"]Anchor timestamp after which the expiration policy applies. Supported anchors:
last_active_at."last_active_at"
-
days: intThe number of days after the anchor time that the vector store will expire.
-
-
expires_at: Optional[int]The Unix timestamp (in seconds) for when the vector store will expire.
-
Example
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
)
vector_store = client.vector_stores.create()
print(vector_store.id)
Response
{
"id": "id",
"created_at": 0,
"file_counts": {
"cancelled": 0,
"completed": 0,
"failed": 0,
"in_progress": 0,
"total": 0
},
"last_active_at": 0,
"metadata": {
"foo": "string"
},
"name": "name",
"object": "vector_store",
"status": "expired",
"usage_bytes": 0,
"expires_after": {
"anchor": "last_active_at",
"days": 1
},
"expires_at": 0
}
Example
from openai import OpenAI
client = OpenAI()
vector_store = client.vector_stores.create(
name="Support FAQ"
)
print(vector_store)
Response
{
"id": "vs_abc123",
"object": "vector_store",
"created_at": 1699061776,
"name": "Support FAQ",
"description": "Contains commonly asked questions and answers, organized by topic.",
"bytes": 139920,
"file_counts": {
"in_progress": 0,
"completed": 3,
"failed": 0,
"cancelled": 0,
"total": 3
}
}
Retrieve vector store
vector_stores.retrieve(strvector_store_id) -> VectorStore
get /vector_stores/{vector_store_id}
Retrieves a vector store.
Parameters
vector_store_id: str
Returns
-
class VectorStore: …A vector store is a collection of processed files can be used by the
file_searchtool.-
id: strThe identifier, which can be referenced in API endpoints.
-
created_at: intThe Unix timestamp (in seconds) for when the vector store was created.
-
file_counts: FileCounts-
cancelled: intThe number of files that were cancelled.
-
completed: intThe number of files that have been successfully processed.
-
failed: intThe number of files that have failed to process.
-
in_progress: intThe number of files that are currently being processed.
-
total: intThe total number of files.
-
-
last_active_at: Optional[int]The Unix timestamp (in seconds) for when the vector store was last active.
-
metadata: Optional[Metadata]Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard.
Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.
-
name: strThe name of the vector store.
-
object: Literal["vector_store"]The object type, which is always
vector_store."vector_store"
-
status: Literal["expired", "in_progress", "completed"]The status of the vector store, which can be either
expired,in_progress, orcompleted. A status ofcompletedindicates that the vector store is ready for use.-
"expired" -
"in_progress" -
"completed"
-
-
usage_bytes: intThe total number of bytes used by the files in the vector store.
-
expires_after: Optional[ExpiresAfter]The expiration policy for a vector store.
-
anchor: Literal["last_active_at"]Anchor timestamp after which the expiration policy applies. Supported anchors:
last_active_at."last_active_at"
-
days: intThe number of days after the anchor time that the vector store will expire.
-
-
expires_at: Optional[int]The Unix timestamp (in seconds) for when the vector store will expire.
-
Example
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
)
vector_store = client.vector_stores.retrieve(
"vector_store_id",
)
print(vector_store.id)
Response
{
"id": "id",
"created_at": 0,
"file_counts": {
"cancelled": 0,
"completed": 0,
"failed": 0,
"in_progress": 0,
"total": 0
},
"last_active_at": 0,
"metadata": {
"foo": "string"
},
"name": "name",
"object": "vector_store",
"status": "expired",
"usage_bytes": 0,
"expires_after": {
"anchor": "last_active_at",
"days": 1
},
"expires_at": 0
}
Example
from openai import OpenAI
client = OpenAI()
vector_store = client.vector_stores.retrieve(
vector_store_id="vs_abc123"
)
print(vector_store)
Response
{
"id": "vs_abc123",
"object": "vector_store",
"created_at": 1699061776
}
Modify vector store
vector_stores.update(strvector_store_id, VectorStoreUpdateParams**kwargs) -> VectorStore
post /vector_stores/{vector_store_id}
Modifies a vector store.
Parameters
-
vector_store_id: str -
expires_after: Optional[ExpiresAfter]The expiration policy for a vector store.
-
anchor: Literal["last_active_at"]Anchor timestamp after which the expiration policy applies. Supported anchors:
last_active_at."last_active_at"
-
days: intThe number of days after the anchor time that the vector store will expire.
-
-
metadata: Optional[Metadata]Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard.
Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.
-
name: Optional[str]The name of the vector store.
Returns
-
class VectorStore: …A vector store is a collection of processed files can be used by the
file_searchtool.-
id: strThe identifier, which can be referenced in API endpoints.
-
created_at: intThe Unix timestamp (in seconds) for when the vector store was created.
-
file_counts: FileCounts-
cancelled: intThe number of files that were cancelled.
-
completed: intThe number of files that have been successfully processed.
-
failed: intThe number of files that have failed to process.
-
in_progress: intThe number of files that are currently being processed.
-
total: intThe total number of files.
-
-
last_active_at: Optional[int]The Unix timestamp (in seconds) for when the vector store was last active.
-
metadata: Optional[Metadata]Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard.
Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.
-
name: strThe name of the vector store.
-
object: Literal["vector_store"]The object type, which is always
vector_store."vector_store"
-
status: Literal["expired", "in_progress", "completed"]The status of the vector store, which can be either
expired,in_progress, orcompleted. A status ofcompletedindicates that the vector store is ready for use.-
"expired" -
"in_progress" -
"completed"
-
-
usage_bytes: intThe total number of bytes used by the files in the vector store.
-
expires_after: Optional[ExpiresAfter]The expiration policy for a vector store.
-
anchor: Literal["last_active_at"]Anchor timestamp after which the expiration policy applies. Supported anchors:
last_active_at."last_active_at"
-
days: intThe number of days after the anchor time that the vector store will expire.
-
-
expires_at: Optional[int]The Unix timestamp (in seconds) for when the vector store will expire.
-
Example
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
)
vector_store = client.vector_stores.update(
vector_store_id="vector_store_id",
)
print(vector_store.id)
Response
{
"id": "id",
"created_at": 0,
"file_counts": {
"cancelled": 0,
"completed": 0,
"failed": 0,
"in_progress": 0,
"total": 0
},
"last_active_at": 0,
"metadata": {
"foo": "string"
},
"name": "name",
"object": "vector_store",
"status": "expired",
"usage_bytes": 0,
"expires_after": {
"anchor": "last_active_at",
"days": 1
},
"expires_at": 0
}
Example
from openai import OpenAI
client = OpenAI()
vector_store = client.vector_stores.update(
vector_store_id="vs_abc123",
name="Support FAQ"
)
print(vector_store)
Response
{
"id": "vs_abc123",
"object": "vector_store",
"created_at": 1699061776,
"name": "Support FAQ",
"description": "Contains commonly asked questions and answers, organized by topic.",
"bytes": 139920,
"file_counts": {
"in_progress": 0,
"completed": 3,
"failed": 0,
"cancelled": 0,
"total": 3
}
}
Delete vector store
vector_stores.delete(strvector_store_id) -> VectorStoreDeleted
delete /vector_stores/{vector_store_id}
Delete a vector store.
Parameters
vector_store_id: str
Returns
-
class VectorStoreDeleted: …-
id: str -
deleted: bool -
object: Literal["vector_store.deleted"]"vector_store.deleted"
-
Example
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
)
vector_store_deleted = client.vector_stores.delete(
"vector_store_id",
)
print(vector_store_deleted.id)
Response
{
"id": "id",
"deleted": true,
"object": "vector_store.deleted"
}
Example
from openai import OpenAI
client = OpenAI()
deleted_vector_store = client.vector_stores.delete(
vector_store_id="vs_abc123"
)
print(deleted_vector_store)
Response
{
id: "vs_abc123",
object: "vector_store.deleted",
deleted: true
}
Search vector store
vector_stores.search(strvector_store_id, VectorStoreSearchParams**kwargs) -> SyncPage[VectorStoreSearchResponse]
post /vector_stores/{vector_store_id}/search
Search a vector store for relevant chunks based on a query and file attributes filter.
Parameters
-
vector_store_id: str -
query: Union[str, Sequence[str]]A query string for a search
-
str -
Sequence[str]
-
-
filters: Optional[Filters]A filter to apply based on file attributes.
-
class ComparisonFilter: …A filter used to compare a specified attribute key to a given value using a defined comparison operation.
-
key: strThe key to compare against the value.
-
type: Literal["eq", "ne", "gt", 5 more]Specifies the comparison operator:
eq,ne,gt,gte,lt,lte,in,nin.-
eq: equals -
ne: not equal -
gt: greater than -
gte: greater than or equal -
lt: less than -
lte: less than or equal -
in: in -
nin: not in -
"eq" -
"ne" -
"gt" -
"gte" -
"lt" -
"lte" -
"in" -
"nin"
-
-
value: Union[str, float, bool, List[Union[str, float]]]The value to compare against the attribute key; supports string, number, or boolean types.
-
str -
float -
bool -
List[Union[str, float]]-
str -
float
-
-
-
-
class CompoundFilter: …Combine multiple filters using
andoror.-
filters: List[Filter]Array of filters to combine. Items can be
ComparisonFilterorCompoundFilter.-
class ComparisonFilter: …A filter used to compare a specified attribute key to a given value using a defined comparison operation.
-
object
-
-
type: Literal["and", "or"]Type of operation:
andoror.-
"and" -
"or"
-
-
-
-
max_num_results: Optional[int]The maximum number of results to return. This number should be between 1 and 50 inclusive.
-
ranking_options: Optional[RankingOptions]Ranking options for search.
-
ranker: Optional[Literal["none", "auto", "default-2024-11-15"]]Enable re-ranking; set to
noneto disable, which can help reduce latency.-
"none" -
"auto" -
"default-2024-11-15"
-
-
score_threshold: Optional[float]
-
-
rewrite_query: Optional[bool]Whether to rewrite the natural language query for vector search.
Returns
-
class VectorStoreSearchResponse: …-
attributes: Optional[Dict[str, Union[str, float, bool]]]Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard. Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters, booleans, or numbers.
-
str -
float -
bool
-
-
content: List[Content]Content chunks from the file.
-
text: strThe text content returned from search.
-
type: Literal["text"]The type of content.
"text"
-
-
file_id: strThe ID of the vector store file.
-
filename: strThe name of the vector store file.
-
score: floatThe similarity score for the result.
-
Example
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
)
page = client.vector_stores.search(
vector_store_id="vs_abc123",
query="string",
)
page = page.data[0]
print(page.file_id)
Response
{
"data": [
{
"attributes": {
"foo": "string"
},
"content": [
{
"text": "text",
"type": "text"
}
],
"file_id": "file_id",
"filename": "filename",
"score": 0
}
],
"has_more": true,
"next_page": "next_page",
"object": "vector_store.search_results.page",
"search_query": [
"string"
]
}
Domain Types
Auto File Chunking Strategy Param
-
class AutoFileChunkingStrategyParam: …The default strategy. This strategy currently uses a
max_chunk_size_tokensof800andchunk_overlap_tokensof400.-
type: Literal["auto"]Always
auto."auto"
-
File Chunking Strategy
-
FileChunkingStrategyThe strategy used to chunk the file.
-
class StaticFileChunkingStrategyObject: …-
static: StaticFileChunkingStrategy-
chunk_overlap_tokens: intThe number of tokens that overlap between chunks. The default value is
400.Note that the overlap must not exceed half of
max_chunk_size_tokens. -
max_chunk_size_tokens: intThe maximum number of tokens in each chunk. The default value is
800. The minimum value is100and the maximum value is4096.
-
-
type: Literal["static"]Always
static."static"
-
-
class OtherFileChunkingStrategyObject: …This is returned when the chunking strategy is unknown. Typically, this is because the file was indexed before the
chunking_strategyconcept was introduced in the API.-
type: Literal["other"]Always
other."other"
-
-
File Chunking Strategy Param
-
FileChunkingStrategyParamThe chunking strategy used to chunk the file(s). If not set, will use the
autostrategy. Only applicable iffile_idsis non-empty.-
class AutoFileChunkingStrategyParam: …The default strategy. This strategy currently uses a
max_chunk_size_tokensof800andchunk_overlap_tokensof400.-
type: Literal["auto"]Always
auto."auto"
-
-
class StaticFileChunkingStrategyObjectParam: …Customize your own chunking strategy by setting chunk size and chunk overlap.
-
static: StaticFileChunkingStrategy-
chunk_overlap_tokens: intThe number of tokens that overlap between chunks. The default value is
400.Note that the overlap must not exceed half of
max_chunk_size_tokens. -
max_chunk_size_tokens: intThe maximum number of tokens in each chunk. The default value is
800. The minimum value is100and the maximum value is4096.
-
-
type: Literal["static"]Always
static."static"
-
-
Other File Chunking Strategy Object
-
class OtherFileChunkingStrategyObject: …This is returned when the chunking strategy is unknown. Typically, this is because the file was indexed before the
chunking_strategyconcept was introduced in the API.-
type: Literal["other"]Always
other."other"
-
Static File Chunking Strategy
-
class StaticFileChunkingStrategy: …-
chunk_overlap_tokens: intThe number of tokens that overlap between chunks. The default value is
400.Note that the overlap must not exceed half of
max_chunk_size_tokens. -
max_chunk_size_tokens: intThe maximum number of tokens in each chunk. The default value is
800. The minimum value is100and the maximum value is4096.
-
Static File Chunking Strategy Object
-
class StaticFileChunkingStrategyObject: …-
static: StaticFileChunkingStrategy-
chunk_overlap_tokens: intThe number of tokens that overlap between chunks. The default value is
400.Note that the overlap must not exceed half of
max_chunk_size_tokens. -
max_chunk_size_tokens: intThe maximum number of tokens in each chunk. The default value is
800. The minimum value is100and the maximum value is4096.
-
-
type: Literal["static"]Always
static."static"
-
Static File Chunking Strategy Object Param
-
class StaticFileChunkingStrategyObjectParam: …Customize your own chunking strategy by setting chunk size and chunk overlap.
-
static: StaticFileChunkingStrategy-
chunk_overlap_tokens: intThe number of tokens that overlap between chunks. The default value is
400.Note that the overlap must not exceed half of
max_chunk_size_tokens. -
max_chunk_size_tokens: intThe maximum number of tokens in each chunk. The default value is
800. The minimum value is100and the maximum value is4096.
-
-
type: Literal["static"]Always
static."static"
-
Vector Store
-
class VectorStore: …A vector store is a collection of processed files can be used by the
file_searchtool.-
id: strThe identifier, which can be referenced in API endpoints.
-
created_at: intThe Unix timestamp (in seconds) for when the vector store was created.
-
file_counts: FileCounts-
cancelled: intThe number of files that were cancelled.
-
completed: intThe number of files that have been successfully processed.
-
failed: intThe number of files that have failed to process.
-
in_progress: intThe number of files that are currently being processed.
-
total: intThe total number of files.
-
-
last_active_at: Optional[int]The Unix timestamp (in seconds) for when the vector store was last active.
-
metadata: Optional[Metadata]Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard.
Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.
-
name: strThe name of the vector store.
-
object: Literal["vector_store"]The object type, which is always
vector_store."vector_store"
-
status: Literal["expired", "in_progress", "completed"]The status of the vector store, which can be either
expired,in_progress, orcompleted. A status ofcompletedindicates that the vector store is ready for use.-
"expired" -
"in_progress" -
"completed"
-
-
usage_bytes: intThe total number of bytes used by the files in the vector store.
-
expires_after: Optional[ExpiresAfter]The expiration policy for a vector store.
-
anchor: Literal["last_active_at"]Anchor timestamp after which the expiration policy applies. Supported anchors:
last_active_at."last_active_at"
-
days: intThe number of days after the anchor time that the vector store will expire.
-
-
expires_at: Optional[int]The Unix timestamp (in seconds) for when the vector store will expire.
-
Vector Store Deleted
-
class VectorStoreDeleted: …-
id: str -
deleted: bool -
object: Literal["vector_store.deleted"]"vector_store.deleted"
-
Vector Store Search Response
-
class VectorStoreSearchResponse: …-
attributes: Optional[Dict[str, Union[str, float, bool]]]Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard. Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters, booleans, or numbers.
-
str -
float -
bool
-
-
content: List[Content]Content chunks from the file.
-
text: strThe text content returned from search.
-
type: Literal["text"]The type of content.
"text"
-
-
file_id: strThe ID of the vector store file.
-
filename: strThe name of the vector store file.
-
score: floatThe similarity score for the result.
-
Files
List vector store files
vector_stores.files.list(strvector_store_id, FileListParams**kwargs) -> SyncCursorPage[VectorStoreFile]
get /vector_stores/{vector_store_id}/files
Returns a list of vector store files.
Parameters
-
vector_store_id: str -
after: Optional[str]A cursor for use in pagination.
afteris an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. -
before: Optional[str]A cursor for use in pagination.
beforeis an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. -
filter: Optional[Literal["in_progress", "completed", "failed", "cancelled"]]Filter by file status. One of
in_progress,completed,failed,cancelled.-
"in_progress" -
"completed" -
"failed" -
"cancelled"
-
-
limit: Optional[int]A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.
-
order: Optional[Literal["asc", "desc"]]Sort order by the
created_attimestamp of the objects.ascfor ascending order anddescfor descending order.-
"asc" -
"desc"
-
Returns
-
class VectorStoreFile: …A list of files attached to a vector store.
-
id: strThe identifier, which can be referenced in API endpoints.
-
created_at: intThe Unix timestamp (in seconds) for when the vector store file was created.
-
last_error: Optional[LastError]The last error associated with this vector store file. Will be
nullif there are no errors.-
code: Literal["server_error", "unsupported_file", "invalid_file"]One of
server_error,unsupported_file, orinvalid_file.-
"server_error" -
"unsupported_file" -
"invalid_file"
-
-
message: strA human-readable description of the error.
-
-
object: Literal["vector_store.file"]The object type, which is always
vector_store.file."vector_store.file"
-
status: Literal["in_progress", "completed", "cancelled", "failed"]The status of the vector store file, which can be either
in_progress,completed,cancelled, orfailed. The statuscompletedindicates that the vector store file is ready for use.-
"in_progress" -
"completed" -
"cancelled" -
"failed"
-
-
usage_bytes: intThe total vector store usage in bytes. Note that this may be different from the original file size.
-
vector_store_id: strThe ID of the vector store that the File is attached to.
-
attributes: Optional[Dict[str, Union[str, float, bool]]]Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard. Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters, booleans, or numbers.
-
str -
float -
bool
-
-
chunking_strategy: Optional[FileChunkingStrategy]The strategy used to chunk the file.
-
class StaticFileChunkingStrategyObject: …-
static: StaticFileChunkingStrategy-
chunk_overlap_tokens: intThe number of tokens that overlap between chunks. The default value is
400.Note that the overlap must not exceed half of
max_chunk_size_tokens. -
max_chunk_size_tokens: intThe maximum number of tokens in each chunk. The default value is
800. The minimum value is100and the maximum value is4096.
-
-
type: Literal["static"]Always
static."static"
-
-
class OtherFileChunkingStrategyObject: …This is returned when the chunking strategy is unknown. Typically, this is because the file was indexed before the
chunking_strategyconcept was introduced in the API.-
type: Literal["other"]Always
other."other"
-
-
-
Example
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
)
page = client.vector_stores.files.list(
vector_store_id="vector_store_id",
)
page = page.data[0]
print(page.id)
Response
{
"data": [
{
"id": "id",
"created_at": 0,
"last_error": {
"code": "server_error",
"message": "message"
},
"object": "vector_store.file",
"status": "in_progress",
"usage_bytes": 0,
"vector_store_id": "vector_store_id",
"attributes": {
"foo": "string"
},
"chunking_strategy": {
"static": {
"chunk_overlap_tokens": 0,
"max_chunk_size_tokens": 100
},
"type": "static"
}
}
],
"first_id": "file-abc123",
"has_more": false,
"last_id": "file-abc456",
"object": "list"
}
Example
from openai import OpenAI
client = OpenAI()
vector_store_files = client.vector_stores.files.list(
vector_store_id="vs_abc123"
)
print(vector_store_files)
Response
{
"object": "list",
"data": [
{
"id": "file-abc123",
"object": "vector_store.file",
"created_at": 1699061776,
"vector_store_id": "vs_abc123"
},
{
"id": "file-abc456",
"object": "vector_store.file",
"created_at": 1699061776,
"vector_store_id": "vs_abc123"
}
],
"first_id": "file-abc123",
"last_id": "file-abc456",
"has_more": false
}
Create vector store file
vector_stores.files.create(strvector_store_id, FileCreateParams**kwargs) -> VectorStoreFile
post /vector_stores/{vector_store_id}/files
Create a vector store file by attaching a File to a vector store.
Parameters
-
vector_store_id: str -
file_id: strA File ID that the vector store should use. Useful for tools like
file_searchthat can access files. For multi-file ingestion, we recommendfile_batchesto minimize per-vector-store write requests. -
attributes: Optional[Dict[str, Union[str, float, bool]]]Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard. Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters, booleans, or numbers.
-
str -
float -
bool
-
-
chunking_strategy: Optional[FileChunkingStrategyParam]The chunking strategy used to chunk the file(s). If not set, will use the
autostrategy. Only applicable iffile_idsis non-empty.-
class AutoFileChunkingStrategyParam: …The default strategy. This strategy currently uses a
max_chunk_size_tokensof800andchunk_overlap_tokensof400.-
type: Literal["auto"]Always
auto."auto"
-
-
class StaticFileChunkingStrategyObjectParam: …Customize your own chunking strategy by setting chunk size and chunk overlap.
-
static: StaticFileChunkingStrategy-
chunk_overlap_tokens: intThe number of tokens that overlap between chunks. The default value is
400.Note that the overlap must not exceed half of
max_chunk_size_tokens. -
max_chunk_size_tokens: intThe maximum number of tokens in each chunk. The default value is
800. The minimum value is100and the maximum value is4096.
-
-
type: Literal["static"]Always
static."static"
-
-
Returns
-
class VectorStoreFile: …A list of files attached to a vector store.
-
id: strThe identifier, which can be referenced in API endpoints.
-
created_at: intThe Unix timestamp (in seconds) for when the vector store file was created.
-
last_error: Optional[LastError]The last error associated with this vector store file. Will be
nullif there are no errors.-
code: Literal["server_error", "unsupported_file", "invalid_file"]One of
server_error,unsupported_file, orinvalid_file.-
"server_error" -
"unsupported_file" -
"invalid_file"
-
-
message: strA human-readable description of the error.
-
-
object: Literal["vector_store.file"]The object type, which is always
vector_store.file."vector_store.file"
-
status: Literal["in_progress", "completed", "cancelled", "failed"]The status of the vector store file, which can be either
in_progress,completed,cancelled, orfailed. The statuscompletedindicates that the vector store file is ready for use.-
"in_progress" -
"completed" -
"cancelled" -
"failed"
-
-
usage_bytes: intThe total vector store usage in bytes. Note that this may be different from the original file size.
-
vector_store_id: strThe ID of the vector store that the File is attached to.
-
attributes: Optional[Dict[str, Union[str, float, bool]]]Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard. Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters, booleans, or numbers.
-
str -
float -
bool
-
-
chunking_strategy: Optional[FileChunkingStrategy]The strategy used to chunk the file.
-
class StaticFileChunkingStrategyObject: …-
static: StaticFileChunkingStrategy-
chunk_overlap_tokens: intThe number of tokens that overlap between chunks. The default value is
400.Note that the overlap must not exceed half of
max_chunk_size_tokens. -
max_chunk_size_tokens: intThe maximum number of tokens in each chunk. The default value is
800. The minimum value is100and the maximum value is4096.
-
-
type: Literal["static"]Always
static."static"
-
-
class OtherFileChunkingStrategyObject: …This is returned when the chunking strategy is unknown. Typically, this is because the file was indexed before the
chunking_strategyconcept was introduced in the API.-
type: Literal["other"]Always
other."other"
-
-
-
Example
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
)
vector_store_file = client.vector_stores.files.create(
vector_store_id="vs_abc123",
file_id="file_id",
)
print(vector_store_file.id)
Response
{
"id": "id",
"created_at": 0,
"last_error": {
"code": "server_error",
"message": "message"
},
"object": "vector_store.file",
"status": "in_progress",
"usage_bytes": 0,
"vector_store_id": "vector_store_id",
"attributes": {
"foo": "string"
},
"chunking_strategy": {
"static": {
"chunk_overlap_tokens": 0,
"max_chunk_size_tokens": 100
},
"type": "static"
}
}
Example
from openai import OpenAI
client = OpenAI()
vector_store_file = client.vector_stores.files.create(
vector_store_id="vs_abc123",
file_id="file-abc123"
)
print(vector_store_file)
Response
{
"id": "file-abc123",
"object": "vector_store.file",
"created_at": 1699061776,
"usage_bytes": 1234,
"vector_store_id": "vs_abcd",
"status": "completed",
"last_error": null
}
Update vector store file attributes
vector_stores.files.update(strfile_id, FileUpdateParams**kwargs) -> VectorStoreFile
post /vector_stores/{vector_store_id}/files/{file_id}
Update attributes on a vector store file.
Parameters
-
vector_store_id: str -
file_id: str -
attributes: Optional[Dict[str, Union[str, float, bool]]]Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard. Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters, booleans, or numbers.
-
str -
float -
bool
-
Returns
-
class VectorStoreFile: …A list of files attached to a vector store.
-
id: strThe identifier, which can be referenced in API endpoints.
-
created_at: intThe Unix timestamp (in seconds) for when the vector store file was created.
-
last_error: Optional[LastError]The last error associated with this vector store file. Will be
nullif there are no errors.-
code: Literal["server_error", "unsupported_file", "invalid_file"]One of
server_error,unsupported_file, orinvalid_file.-
"server_error" -
"unsupported_file" -
"invalid_file"
-
-
message: strA human-readable description of the error.
-
-
object: Literal["vector_store.file"]The object type, which is always
vector_store.file."vector_store.file"
-
status: Literal["in_progress", "completed", "cancelled", "failed"]The status of the vector store file, which can be either
in_progress,completed,cancelled, orfailed. The statuscompletedindicates that the vector store file is ready for use.-
"in_progress" -
"completed" -
"cancelled" -
"failed"
-
-
usage_bytes: intThe total vector store usage in bytes. Note that this may be different from the original file size.
-
vector_store_id: strThe ID of the vector store that the File is attached to.
-
attributes: Optional[Dict[str, Union[str, float, bool]]]Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard. Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters, booleans, or numbers.
-
str -
float -
bool
-
-
chunking_strategy: Optional[FileChunkingStrategy]The strategy used to chunk the file.
-
class StaticFileChunkingStrategyObject: …-
static: StaticFileChunkingStrategy-
chunk_overlap_tokens: intThe number of tokens that overlap between chunks. The default value is
400.Note that the overlap must not exceed half of
max_chunk_size_tokens. -
max_chunk_size_tokens: intThe maximum number of tokens in each chunk. The default value is
800. The minimum value is100and the maximum value is4096.
-
-
type: Literal["static"]Always
static."static"
-
-
class OtherFileChunkingStrategyObject: …This is returned when the chunking strategy is unknown. Typically, this is because the file was indexed before the
chunking_strategyconcept was introduced in the API.-
type: Literal["other"]Always
other."other"
-
-
-
Example
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
)
vector_store_file = client.vector_stores.files.update(
file_id="file-abc123",
vector_store_id="vs_abc123",
attributes={
"foo": "string"
},
)
print(vector_store_file.id)
Response
{
"id": "id",
"created_at": 0,
"last_error": {
"code": "server_error",
"message": "message"
},
"object": "vector_store.file",
"status": "in_progress",
"usage_bytes": 0,
"vector_store_id": "vector_store_id",
"attributes": {
"foo": "string"
},
"chunking_strategy": {
"static": {
"chunk_overlap_tokens": 0,
"max_chunk_size_tokens": 100
},
"type": "static"
}
}
Retrieve vector store file
vector_stores.files.retrieve(strfile_id, FileRetrieveParams**kwargs) -> VectorStoreFile
get /vector_stores/{vector_store_id}/files/{file_id}
Retrieves a vector store file.
Parameters
-
vector_store_id: str -
file_id: str
Returns
-
class VectorStoreFile: …A list of files attached to a vector store.
-
id: strThe identifier, which can be referenced in API endpoints.
-
created_at: intThe Unix timestamp (in seconds) for when the vector store file was created.
-
last_error: Optional[LastError]The last error associated with this vector store file. Will be
nullif there are no errors.-
code: Literal["server_error", "unsupported_file", "invalid_file"]One of
server_error,unsupported_file, orinvalid_file.-
"server_error" -
"unsupported_file" -
"invalid_file"
-
-
message: strA human-readable description of the error.
-
-
object: Literal["vector_store.file"]The object type, which is always
vector_store.file."vector_store.file"
-
status: Literal["in_progress", "completed", "cancelled", "failed"]The status of the vector store file, which can be either
in_progress,completed,cancelled, orfailed. The statuscompletedindicates that the vector store file is ready for use.-
"in_progress" -
"completed" -
"cancelled" -
"failed"
-
-
usage_bytes: intThe total vector store usage in bytes. Note that this may be different from the original file size.
-
vector_store_id: strThe ID of the vector store that the File is attached to.
-
attributes: Optional[Dict[str, Union[str, float, bool]]]Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard. Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters, booleans, or numbers.
-
str -
float -
bool
-
-
chunking_strategy: Optional[FileChunkingStrategy]The strategy used to chunk the file.
-
class StaticFileChunkingStrategyObject: …-
static: StaticFileChunkingStrategy-
chunk_overlap_tokens: intThe number of tokens that overlap between chunks. The default value is
400.Note that the overlap must not exceed half of
max_chunk_size_tokens. -
max_chunk_size_tokens: intThe maximum number of tokens in each chunk. The default value is
800. The minimum value is100and the maximum value is4096.
-
-
type: Literal["static"]Always
static."static"
-
-
class OtherFileChunkingStrategyObject: …This is returned when the chunking strategy is unknown. Typically, this is because the file was indexed before the
chunking_strategyconcept was introduced in the API.-
type: Literal["other"]Always
other."other"
-
-
-
Example
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
)
vector_store_file = client.vector_stores.files.retrieve(
file_id="file-abc123",
vector_store_id="vs_abc123",
)
print(vector_store_file.id)
Response
{
"id": "id",
"created_at": 0,
"last_error": {
"code": "server_error",
"message": "message"
},
"object": "vector_store.file",
"status": "in_progress",
"usage_bytes": 0,
"vector_store_id": "vector_store_id",
"attributes": {
"foo": "string"
},
"chunking_strategy": {
"static": {
"chunk_overlap_tokens": 0,
"max_chunk_size_tokens": 100
},
"type": "static"
}
}
Example
from openai import OpenAI
client = OpenAI()
vector_store_file = client.vector_stores.files.retrieve(
vector_store_id="vs_abc123",
file_id="file-abc123"
)
print(vector_store_file)
Response
{
"id": "file-abc123",
"object": "vector_store.file",
"created_at": 1699061776,
"vector_store_id": "vs_abcd",
"status": "completed",
"last_error": null
}
Delete vector store file
vector_stores.files.delete(strfile_id, FileDeleteParams**kwargs) -> VectorStoreFileDeleted
delete /vector_stores/{vector_store_id}/files/{file_id}
Delete a vector store file. This will remove the file from the vector store but the file itself will not be deleted. To delete the file, use the delete file endpoint.
Parameters
-
vector_store_id: str -
file_id: str
Returns
-
class VectorStoreFileDeleted: …-
id: str -
deleted: bool -
object: Literal["vector_store.file.deleted"]"vector_store.file.deleted"
-
Example
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
)
vector_store_file_deleted = client.vector_stores.files.delete(
file_id="file_id",
vector_store_id="vector_store_id",
)
print(vector_store_file_deleted.id)
Response
{
"id": "id",
"deleted": true,
"object": "vector_store.file.deleted"
}
Example
from openai import OpenAI
client = OpenAI()
deleted_vector_store_file = client.vector_stores.files.delete(
vector_store_id="vs_abc123",
file_id="file-abc123"
)
print(deleted_vector_store_file)
Response
{
id: "file-abc123",
object: "vector_store.file.deleted",
deleted: true
}
Retrieve vector store file content
vector_stores.files.content(strfile_id, FileContentParams**kwargs) -> SyncPage[FileContentResponse]
get /vector_stores/{vector_store_id}/files/{file_id}/content
Retrieve the parsed contents of a vector store file.
Parameters
-
vector_store_id: str -
file_id: str
Returns
-
class FileContentResponse: …-
text: Optional[str]The text content
-
type: Optional[str]The content type (currently only
"text")
-
Example
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
)
page = client.vector_stores.files.content(
file_id="file-abc123",
vector_store_id="vs_abc123",
)
page = page.data[0]
print(page.text)
Response
{
"data": [
{
"text": "text",
"type": "type"
}
],
"has_more": true,
"next_page": "next_page",
"object": "vector_store.file_content.page"
}
Domain Types
Vector Store File
-
class VectorStoreFile: …A list of files attached to a vector store.
-
id: strThe identifier, which can be referenced in API endpoints.
-
created_at: intThe Unix timestamp (in seconds) for when the vector store file was created.
-
last_error: Optional[LastError]The last error associated with this vector store file. Will be
nullif there are no errors.-
code: Literal["server_error", "unsupported_file", "invalid_file"]One of
server_error,unsupported_file, orinvalid_file.-
"server_error" -
"unsupported_file" -
"invalid_file"
-
-
message: strA human-readable description of the error.
-
-
object: Literal["vector_store.file"]The object type, which is always
vector_store.file."vector_store.file"
-
status: Literal["in_progress", "completed", "cancelled", "failed"]The status of the vector store file, which can be either
in_progress,completed,cancelled, orfailed. The statuscompletedindicates that the vector store file is ready for use.-
"in_progress" -
"completed" -
"cancelled" -
"failed"
-
-
usage_bytes: intThe total vector store usage in bytes. Note that this may be different from the original file size.
-
vector_store_id: strThe ID of the vector store that the File is attached to.
-
attributes: Optional[Dict[str, Union[str, float, bool]]]Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard. Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters, booleans, or numbers.
-
str -
float -
bool
-
-
chunking_strategy: Optional[FileChunkingStrategy]The strategy used to chunk the file.
-
class StaticFileChunkingStrategyObject: …-
static: StaticFileChunkingStrategy-
chunk_overlap_tokens: intThe number of tokens that overlap between chunks. The default value is
400.Note that the overlap must not exceed half of
max_chunk_size_tokens. -
max_chunk_size_tokens: intThe maximum number of tokens in each chunk. The default value is
800. The minimum value is100and the maximum value is4096.
-
-
type: Literal["static"]Always
static."static"
-
-
class OtherFileChunkingStrategyObject: …This is returned when the chunking strategy is unknown. Typically, this is because the file was indexed before the
chunking_strategyconcept was introduced in the API.-
type: Literal["other"]Always
other."other"
-
-
-
Vector Store File Deleted
-
class VectorStoreFileDeleted: …-
id: str -
deleted: bool -
object: Literal["vector_store.file.deleted"]"vector_store.file.deleted"
-
File Content Response
-
class FileContentResponse: …-
text: Optional[str]The text content
-
type: Optional[str]The content type (currently only
"text")
-
File Batches
Create vector store file batch
vector_stores.file_batches.create(strvector_store_id, FileBatchCreateParams**kwargs) -> VectorStoreFileBatch
post /vector_stores/{vector_store_id}/file_batches
Create a vector store file batch.
Parameters
-
vector_store_id: str -
attributes: Optional[Dict[str, Union[str, float, bool]]]Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard. Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters, booleans, or numbers.
-
str -
float -
bool
-
-
chunking_strategy: Optional[FileChunkingStrategyParam]The chunking strategy used to chunk the file(s). If not set, will use the
autostrategy. Only applicable iffile_idsis non-empty.-
class AutoFileChunkingStrategyParam: …The default strategy. This strategy currently uses a
max_chunk_size_tokensof800andchunk_overlap_tokensof400.-
type: Literal["auto"]Always
auto."auto"
-
-
class StaticFileChunkingStrategyObjectParam: …Customize your own chunking strategy by setting chunk size and chunk overlap.
-
static: StaticFileChunkingStrategy-
chunk_overlap_tokens: intThe number of tokens that overlap between chunks. The default value is
400.Note that the overlap must not exceed half of
max_chunk_size_tokens. -
max_chunk_size_tokens: intThe maximum number of tokens in each chunk. The default value is
800. The minimum value is100and the maximum value is4096.
-
-
type: Literal["static"]Always
static."static"
-
-
-
file_ids: Optional[Sequence[str]]A list of File IDs that the vector store should use. Useful for tools like
file_searchthat can access files. Ifattributesorchunking_strategyare provided, they will be applied to all files in the batch. The maximum batch size is 2000 files. This endpoint is recommended for multi-file ingestion and helps reduce per-vector-store write request pressure. Mutually exclusive withfiles. -
files: Optional[Iterable[File]]A list of objects that each include a
file_idplus optionalattributesorchunking_strategy. Use this when you need to override metadata for specific files. The globalattributesorchunking_strategywill be ignored and must be specified for each file. The maximum batch size is 2000 files. This endpoint is recommended for multi-file ingestion and helps reduce per-vector-store write request pressure. Mutually exclusive withfile_ids.-
file_id: strA File ID that the vector store should use. Useful for tools like
file_searchthat can access files. For multi-file ingestion, we recommendfile_batchesto minimize per-vector-store write requests. -
attributes: Optional[Dict[str, Union[str, float, bool]]]Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard. Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters, booleans, or numbers.
-
str -
float -
bool
-
-
chunking_strategy: Optional[FileChunkingStrategyParam]The chunking strategy used to chunk the file(s). If not set, will use the
autostrategy. Only applicable iffile_idsis non-empty.
-
Returns
-
class VectorStoreFileBatch: …A batch of files attached to a vector store.
-
id: strThe identifier, which can be referenced in API endpoints.
-
created_at: intThe Unix timestamp (in seconds) for when the vector store files batch was created.
-
file_counts: FileCounts-
cancelled: intThe number of files that where cancelled.
-
completed: intThe number of files that have been processed.
-
failed: intThe number of files that have failed to process.
-
in_progress: intThe number of files that are currently being processed.
-
total: intThe total number of files.
-
-
object: Literal["vector_store.files_batch"]The object type, which is always
vector_store.file_batch."vector_store.files_batch"
-
status: Literal["in_progress", "completed", "cancelled", "failed"]The status of the vector store files batch, which can be either
in_progress,completed,cancelledorfailed.-
"in_progress" -
"completed" -
"cancelled" -
"failed"
-
-
vector_store_id: strThe ID of the vector store that the File is attached to.
-
Example
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
)
vector_store_file_batch = client.vector_stores.file_batches.create(
vector_store_id="vs_abc123",
)
print(vector_store_file_batch.id)
Response
{
"id": "id",
"created_at": 0,
"file_counts": {
"cancelled": 0,
"completed": 0,
"failed": 0,
"in_progress": 0,
"total": 0
},
"object": "vector_store.files_batch",
"status": "in_progress",
"vector_store_id": "vector_store_id"
}
Example
from openai import OpenAI
client = OpenAI()
vector_store_file_batch = client.vector_stores.file_batches.create(
vector_store_id="vs_abc123",
files=[
{
"file_id": "file-abc123",
"attributes": {"category": "finance"},
},
{
"file_id": "file-abc456",
"chunking_strategy": {
"type": "static",
"max_chunk_size_tokens": 1200,
"chunk_overlap_tokens": 200,
},
},
],
)
print(vector_store_file_batch)
Response
{
"id": "vsfb_abc123",
"object": "vector_store.file_batch",
"created_at": 1699061776,
"vector_store_id": "vs_abc123",
"status": "in_progress",
"file_counts": {
"in_progress": 1,
"completed": 1,
"failed": 0,
"cancelled": 0,
"total": 0,
}
}
Retrieve vector store file batch
vector_stores.file_batches.retrieve(strbatch_id, FileBatchRetrieveParams**kwargs) -> VectorStoreFileBatch
get /vector_stores/{vector_store_id}/file_batches/{batch_id}
Retrieves a vector store file batch.
Parameters
-
vector_store_id: str -
batch_id: str
Returns
-
class VectorStoreFileBatch: …A batch of files attached to a vector store.
-
id: strThe identifier, which can be referenced in API endpoints.
-
created_at: intThe Unix timestamp (in seconds) for when the vector store files batch was created.
-
file_counts: FileCounts-
cancelled: intThe number of files that where cancelled.
-
completed: intThe number of files that have been processed.
-
failed: intThe number of files that have failed to process.
-
in_progress: intThe number of files that are currently being processed.
-
total: intThe total number of files.
-
-
object: Literal["vector_store.files_batch"]The object type, which is always
vector_store.file_batch."vector_store.files_batch"
-
status: Literal["in_progress", "completed", "cancelled", "failed"]The status of the vector store files batch, which can be either
in_progress,completed,cancelledorfailed.-
"in_progress" -
"completed" -
"cancelled" -
"failed"
-
-
vector_store_id: strThe ID of the vector store that the File is attached to.
-
Example
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
)
vector_store_file_batch = client.vector_stores.file_batches.retrieve(
batch_id="vsfb_abc123",
vector_store_id="vs_abc123",
)
print(vector_store_file_batch.id)
Response
{
"id": "id",
"created_at": 0,
"file_counts": {
"cancelled": 0,
"completed": 0,
"failed": 0,
"in_progress": 0,
"total": 0
},
"object": "vector_store.files_batch",
"status": "in_progress",
"vector_store_id": "vector_store_id"
}
Example
from openai import OpenAI
client = OpenAI()
vector_store_file_batch = client.vector_stores.file_batches.retrieve(
vector_store_id="vs_abc123",
batch_id="vsfb_abc123"
)
print(vector_store_file_batch)
Response
{
"id": "vsfb_abc123",
"object": "vector_store.file_batch",
"created_at": 1699061776,
"vector_store_id": "vs_abc123",
"status": "in_progress",
"file_counts": {
"in_progress": 1,
"completed": 1,
"failed": 0,
"cancelled": 0,
"total": 0,
}
}
Cancel vector store file batch
vector_stores.file_batches.cancel(strbatch_id, FileBatchCancelParams**kwargs) -> VectorStoreFileBatch
post /vector_stores/{vector_store_id}/file_batches/{batch_id}/cancel
Cancel a vector store file batch. This attempts to cancel the processing of files in this batch as soon as possible.
Parameters
-
vector_store_id: str -
batch_id: str
Returns
-
class VectorStoreFileBatch: …A batch of files attached to a vector store.
-
id: strThe identifier, which can be referenced in API endpoints.
-
created_at: intThe Unix timestamp (in seconds) for when the vector store files batch was created.
-
file_counts: FileCounts-
cancelled: intThe number of files that where cancelled.
-
completed: intThe number of files that have been processed.
-
failed: intThe number of files that have failed to process.
-
in_progress: intThe number of files that are currently being processed.
-
total: intThe total number of files.
-
-
object: Literal["vector_store.files_batch"]The object type, which is always
vector_store.file_batch."vector_store.files_batch"
-
status: Literal["in_progress", "completed", "cancelled", "failed"]The status of the vector store files batch, which can be either
in_progress,completed,cancelledorfailed.-
"in_progress" -
"completed" -
"cancelled" -
"failed"
-
-
vector_store_id: strThe ID of the vector store that the File is attached to.
-
Example
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
)
vector_store_file_batch = client.vector_stores.file_batches.cancel(
batch_id="batch_id",
vector_store_id="vector_store_id",
)
print(vector_store_file_batch.id)
Response
{
"id": "id",
"created_at": 0,
"file_counts": {
"cancelled": 0,
"completed": 0,
"failed": 0,
"in_progress": 0,
"total": 0
},
"object": "vector_store.files_batch",
"status": "in_progress",
"vector_store_id": "vector_store_id"
}
Example
from openai import OpenAI
client = OpenAI()
deleted_vector_store_file_batch = client.vector_stores.file_batches.cancel(
vector_store_id="vs_abc123",
file_batch_id="vsfb_abc123"
)
print(deleted_vector_store_file_batch)
Response
{
"id": "vsfb_abc123",
"object": "vector_store.file_batch",
"created_at": 1699061776,
"vector_store_id": "vs_abc123",
"status": "in_progress",
"file_counts": {
"in_progress": 12,
"completed": 3,
"failed": 0,
"cancelled": 0,
"total": 15,
}
}
List vector store files in a batch
vector_stores.file_batches.list_files(strbatch_id, FileBatchListFilesParams**kwargs) -> SyncCursorPage[VectorStoreFile]
get /vector_stores/{vector_store_id}/file_batches/{batch_id}/files
Returns a list of vector store files in a batch.
Parameters
-
vector_store_id: str -
batch_id: str -
after: Optional[str]A cursor for use in pagination.
afteris an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. -
before: Optional[str]A cursor for use in pagination.
beforeis an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. -
filter: Optional[Literal["in_progress", "completed", "failed", "cancelled"]]Filter by file status. One of
in_progress,completed,failed,cancelled.-
"in_progress" -
"completed" -
"failed" -
"cancelled"
-
-
limit: Optional[int]A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.
-
order: Optional[Literal["asc", "desc"]]Sort order by the
created_attimestamp of the objects.ascfor ascending order anddescfor descending order.-
"asc" -
"desc"
-
Returns
-
class VectorStoreFile: …A list of files attached to a vector store.
-
id: strThe identifier, which can be referenced in API endpoints.
-
created_at: intThe Unix timestamp (in seconds) for when the vector store file was created.
-
last_error: Optional[LastError]The last error associated with this vector store file. Will be
nullif there are no errors.-
code: Literal["server_error", "unsupported_file", "invalid_file"]One of
server_error,unsupported_file, orinvalid_file.-
"server_error" -
"unsupported_file" -
"invalid_file"
-
-
message: strA human-readable description of the error.
-
-
object: Literal["vector_store.file"]The object type, which is always
vector_store.file."vector_store.file"
-
status: Literal["in_progress", "completed", "cancelled", "failed"]The status of the vector store file, which can be either
in_progress,completed,cancelled, orfailed. The statuscompletedindicates that the vector store file is ready for use.-
"in_progress" -
"completed" -
"cancelled" -
"failed"
-
-
usage_bytes: intThe total vector store usage in bytes. Note that this may be different from the original file size.
-
vector_store_id: strThe ID of the vector store that the File is attached to.
-
attributes: Optional[Dict[str, Union[str, float, bool]]]Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard. Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters, booleans, or numbers.
-
str -
float -
bool
-
-
chunking_strategy: Optional[FileChunkingStrategy]The strategy used to chunk the file.
-
class StaticFileChunkingStrategyObject: …-
static: StaticFileChunkingStrategy-
chunk_overlap_tokens: intThe number of tokens that overlap between chunks. The default value is
400.Note that the overlap must not exceed half of
max_chunk_size_tokens. -
max_chunk_size_tokens: intThe maximum number of tokens in each chunk. The default value is
800. The minimum value is100and the maximum value is4096.
-
-
type: Literal["static"]Always
static."static"
-
-
class OtherFileChunkingStrategyObject: …This is returned when the chunking strategy is unknown. Typically, this is because the file was indexed before the
chunking_strategyconcept was introduced in the API.-
type: Literal["other"]Always
other."other"
-
-
-
Example
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
)
page = client.vector_stores.file_batches.list_files(
batch_id="batch_id",
vector_store_id="vector_store_id",
)
page = page.data[0]
print(page.id)
Response
{
"data": [
{
"id": "id",
"created_at": 0,
"last_error": {
"code": "server_error",
"message": "message"
},
"object": "vector_store.file",
"status": "in_progress",
"usage_bytes": 0,
"vector_store_id": "vector_store_id",
"attributes": {
"foo": "string"
},
"chunking_strategy": {
"static": {
"chunk_overlap_tokens": 0,
"max_chunk_size_tokens": 100
},
"type": "static"
}
}
],
"first_id": "file-abc123",
"has_more": false,
"last_id": "file-abc456",
"object": "list"
}
Example
from openai import OpenAI
client = OpenAI()
vector_store_files = client.vector_stores.file_batches.list_files(
vector_store_id="vs_abc123",
batch_id="vsfb_abc123"
)
print(vector_store_files)
Response
{
"object": "list",
"data": [
{
"id": "file-abc123",
"object": "vector_store.file",
"created_at": 1699061776,
"vector_store_id": "vs_abc123"
},
{
"id": "file-abc456",
"object": "vector_store.file",
"created_at": 1699061776,
"vector_store_id": "vs_abc123"
}
],
"first_id": "file-abc123",
"last_id": "file-abc456",
"has_more": false
}
Domain Types
Vector Store File Batch
-
class VectorStoreFileBatch: …A batch of files attached to a vector store.
-
id: strThe identifier, which can be referenced in API endpoints.
-
created_at: intThe Unix timestamp (in seconds) for when the vector store files batch was created.
-
file_counts: FileCounts-
cancelled: intThe number of files that where cancelled.
-
completed: intThe number of files that have been processed.
-
failed: intThe number of files that have failed to process.
-
in_progress: intThe number of files that are currently being processed.
-
total: intThe total number of files.
-
-
object: Literal["vector_store.files_batch"]The object type, which is always
vector_store.file_batch."vector_store.files_batch"
-
status: Literal["in_progress", "completed", "cancelled", "failed"]The status of the vector store files batch, which can be either
in_progress,completed,cancelledorfailed.-
"in_progress" -
"completed" -
"cancelled" -
"failed"
-
-
vector_store_id: strThe ID of the vector store that the File is attached to.
-