mirror of
https://gitlab.com/gitlab-org/gitlab-foss.git
synced 2025-08-01 16:04:19 +00:00
2.3 KiB
2.3 KiB
Migrations
Create a file in ActiveContext::Config.migrations_path
.
Data types
ActiveContext supports several field types for defining collection schemas:
bigint
: For large numeric values (acceptsindex: true/false
, defaults tofalse
)integer
: For standard numeric values (acceptsindex: true/false
, defaults tofalse
)smallint
: For small numeric values (acceptsindex: true/false
, defaults tofalse
)boolean
: For boolean values (acceptsindex: true/false
, defaults tofalse
)keyword
: For exact-match searchable string fields (always indexed, noindex
option)text
: For full-text searchable content (acceptsindex: true/false
, defaults tofalse
)vector
: For embedding vectors (acceptsindex: true/false
, defaults totrue
), requiresdimensions:
specification
Migration to create a collection
# frozen_string_literal: true
class CreateMergeRequests < ActiveContext::Migration[1.0]
milestone '17.9'
def migrate!
create_collection :merge_requests, number_of_partitions: 3 do |c|
c.bigint :issue_id, index: true
c.bigint :namespace_id, index: true
c.integer :iid, index: true
c.smallint :priority, index: true
c.boolean :is_draft
c.keyword :traversal_ids
c.text :description
c.vector :embeddings, dimensions: 768
end
end
end
Migration to update a collection's metadata
Use the update_collection_metadata
method to set metadata for a collection:
update_collection_metadata(collection: collection, metadata: metadata)
Updating indexing_embedding_versions
# frozen_string_literal: true
class NAME < ActiveContext::Migration[1.0]
milestone '%MILESTONE'
def migrate!
update_collection_metadata(collection: collection, metadata: metadata)
end
def metadata
{ indexing_embedding_versions: [1, 2] }
end
def collection
Ai::Context::Collections::MergeRequest
end
end
Updating search_embedding_version
# frozen_string_literal: true
class NAME < ActiveContext::Migration[1.0]
milestone '%MILESTONE'
def migrate!
update_collection_metadata(collection: collection, metadata: metadata)
end
def metadata
{ search_embedding_version: 1 }
end
def collection
Ai::Context::Collections::MergeRequest
end
end