This Terraform module provides a streamlined interface for creating and managing OpenAI Vector Stores. Vector stores allow you to store and search through vector embeddings of files for use with tools like file_search in assistants.
- Create and manage OpenAI Vector Stores
- Add files to Vector Stores individually or in batches
- Configure chunking strategies for optimal embedding extraction
- Set expiration policies for Vector Stores
- Attach metadata to Vector Stores and files
module "knowledge_base" {
source = "../../modules/vector_store"
name = "Company Knowledge Base"
}module "support_faq" {
source = "../../modules/vector_store"
name = "Support FAQ"
file_ids = [
openai_file.faq_document.id,
openai_file.troubleshooting_guide.id
]
# Add files individually (default)
use_file_batches = false
# Add metadata
metadata = {
"department" = "support",
"version" = "1.0"
}
}module "product_documentation" {
source = "../../modules/vector_store"
name = "Product Documentation"
file_ids = [
openai_file.user_manual.id,
openai_file.api_reference.id,
openai_file.examples.id
]
# Use file batches for better performance with many files
use_file_batches = true
# Optional: Specify chunking strategy
chunking_strategy = {
type = "fixed",
size = 1000
}
# Optional: Set expiration
expires_after = {
days = 90
}
}| Name | Description | Type | Default | Required |
|---|---|---|---|---|
name |
The name of the vector store | string |
n/a | yes |
file_ids |
A list of File IDs that the vector store should use | list(string) |
[] |
no |
metadata |
Set of key-value pairs that can be attached to the vector store | map(string) |
{} |
no |
chunking_strategy |
The chunking strategy used to chunk the files | object |
{type = "auto"} |
no |
expires_after |
The expiration policy for the vector store | object |
null |
no |
use_file_batches |
Whether to use file batches for adding files | bool |
false |
no |
file_attributes |
Set of key-value pairs for file objects | map(string) |
{} |
no |
The chunking_strategy variable accepts the following formats:
# Auto (default)
chunking_strategy = {
type = "auto"
}
# Fixed size chunks
chunking_strategy = {
type = "fixed"
size = 1000 # Characters per chunk
}
# Semantic chunking
chunking_strategy = {
type = "semantic"
max_tokens = 300 # Maximum tokens per chunk
}The expires_after variable accepts the following formats:
# Expire after a number of days
expires_after = {
days = 30
}
# Never expire
expires_after = {
never = true
}| Name | Description |
|---|---|
id |
The ID of the created vector store |
name |
The name of the vector store |
created_at |
The timestamp when the vector store was created |
file_count |
The number of files in the vector store |
object |
The type of object (always 'vector_store') |
status |
The current status of the vector store |
The module creates the following resources:
- An
openai_vector_storeresource to manage the vector store - Either:
- Multiple
openai_vector_store_fileresources (whenuse_file_batches = false) - A single
openai_vector_store_file_batchresource (whenuse_file_batches = true)
- Multiple
- File IDs must refer to files that have already been uploaded to OpenAI
- Files must have the appropriate purpose (e.g., "assistants")
- Vector stores are in beta and require the
assistants=v2beta header - When working with many files, using file batches (
use_file_batches = true) is more efficient - The maximum number of key-value pairs in metadata and attributes is 16
Error: File not found or not accessible
Solution:
- Verify that the file ID is correct
- Ensure the file has been uploaded to OpenAI
- Check that the file has the appropriate purpose
Error: Rate limit exceeded
Solution:
- Implement exponential backoff and retry logic
- Reduce the frequency of requests to the API