Skip to content

Create vector store file

vector_stores.files.create(vector_store_id, **kwargs) -> VectorStoreFile { id, created_at, last_error, 6 more }
POST/vector_stores/{vector_store_id}/files

Create a vector store file by attaching a File to a vector store.

ParametersExpand Collapse
vector_store_id: String
file_id: String

A File ID that the vector store should use. Useful for tools like file_search that can access files.

attributes: Hash[Symbol, String | 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.

Accepts one of the following:
String
Float
bool
chunking_strategy: FileChunkingStrategyParam

The chunking strategy used to chunk the file(s). If not set, will use the auto strategy. Only applicable if file_ids is non-empty.

Accepts one of the following:
class AutoFileChunkingStrategyParam { type }

The default strategy. This strategy currently uses a max_chunk_size_tokens of 800 and chunk_overlap_tokens of 400.

type: :auto

Always auto.

class StaticFileChunkingStrategyObjectParam { static, type }

Customize your own chunking strategy by setting chunk size and chunk overlap.

static: StaticFileChunkingStrategy { chunk_overlap_tokens, max_chunk_size_tokens }
chunk_overlap_tokens: Integer

The 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: Integer

The maximum number of tokens in each chunk. The default value is 800. The minimum value is 100 and the maximum value is 4096.

minimum100
maximum4096
type: :static

Always static.

ReturnsExpand Collapse
class VectorStoreFile { id, created_at, last_error, 6 more }

A list of files attached to a vector store.

id: String

The identifier, which can be referenced in API endpoints.

created_at: Integer

The Unix timestamp (in seconds) for when the vector store file was created.

last_error: { code, message}

The last error associated with this vector store file. Will be null if there are no errors.

code: :server_error | :unsupported_file | :invalid_file

One of server_error, unsupported_file, or invalid_file.

Accepts one of the following:
:server_error
:unsupported_file
:invalid_file
message: String

A human-readable description of the error.

object: :"vector_store.file"

The object type, which is always vector_store.file.

status: :in_progress | :completed | :cancelled | :failed

The status of the vector store file, which can be either in_progress, completed, cancelled, or failed. The status completed indicates that the vector store file is ready for use.

Accepts one of the following:
:in_progress
:completed
:cancelled
:failed
usage_bytes: Integer

The total vector store usage in bytes. Note that this may be different from the original file size.

vector_store_id: String

The ID of the vector store that the File is attached to.

attributes: Hash[Symbol, String | 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.

Accepts one of the following:
String
Float
bool
chunking_strategy: FileChunkingStrategy

The strategy used to chunk the file.

Accepts one of the following:
class StaticFileChunkingStrategyObject { static, type }
static: StaticFileChunkingStrategy { chunk_overlap_tokens, max_chunk_size_tokens }
chunk_overlap_tokens: Integer

The 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: Integer

The maximum number of tokens in each chunk. The default value is 800. The minimum value is 100 and the maximum value is 4096.

minimum100
maximum4096
type: :static

Always static.

class OtherFileChunkingStrategyObject { type }

This is returned when the chunking strategy is unknown. Typically, this is because the file was indexed before the chunking_strategy concept was introduced in the API.

type: :other

Always other.

Create vector store file

require "openai"

openai = OpenAI::Client.new(api_key: "My API Key")

vector_store_file = openai.vector_stores.files.create("vs_abc123", file_id: "file_id")

puts(vector_store_file)
{
  "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"
  }
}
Returns Examples
{
  "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"
  }
}