creates a new empty vector database.
CreateVectorDatabase[{vec1,…}]
initializes the database with the collection of vectors veci.
CreateVectorDatabase[{vec1,…}{val1,…}]
associates the value vali to the vector veci.
CreateVectorDatabase[data,name]
gives the vector database the specified name.
CreateVectorDatabase
creates a new empty vector database.
CreateVectorDatabase[{vec1,…}]
initializes the database with the collection of vectors veci.
CreateVectorDatabase[{vec1,…}{val1,…}]
associates the value vali to the vector veci.
CreateVectorDatabase[data,name]
gives the vector database the specified name.
Details and Options
- CreateVectorDatabase initializes a new vector database to store and manage high-dimensional data for efficient search and retrieval.
- Typical applications of vector databases include recommendation systems, image and text retrieval, and similarity searches in large datasets.
- Possible values for data include:
-
{vec1,…} a list of vectors {vec1val1,…} a list of vectors and associated values {vec1,…}{val1,…} a rule between vectors and values - A list of scalars is interpreted as a list of one-dimensional vectors. »
- Accepted forms of vali include:
-
"string" string labels <|"tag1"v1,…|> an association of tags and metadata values - The database name must be a string.
- The following options can be specified:
-
DistanceFunction EuclideanDistance how to compute the vector distance FeatureExtractor Identity how to convert the input to a vector GeneratedAssetLocation $GeneratedAssetLocation where to save the database OverwriteTarget Automatic whether to overwrite an existing location WorkingPrecision Automatic numerical precision - Possible values for DistanceFunction include EuclideanDistance, SquaredEuclideanDistance, CosineDistance, JaccardDissimilarity and HammingDistance.
- Possible settings for WorkingPrecision include:
-
"Integer8" signed 8-bit integers from
through 127"Real32" single-precision real (32 bit) "Real64" double-precision real (64 bit)
Examples
open all close allBasic Examples (2)
Create an empty VectorDatabaseObject:
CreateVectorDatabase[]Create a database with a specific name and initialize it with a list of vectors:
database = CreateVectorDatabase[RandomReal[1, {10, 4}], "myDB"]Search the database by similarity:
VectorDatabaseSearch[database, {1, 1, 1, 1}]Scope (5)
Data Sources (3)
Metadata (2)
Initialize the database with both vectors and metadata:
CreateVectorDatabase[{{1, 2, 3} -> "A", {4, 5, 6} -> "B"}]Specify the metadata as a separate list:
CreateVectorDatabase[{{1, 2, 3}, {4, 5, 6}} -> {"A", "B"}]Specify the metadata with tags as an Association:
CreateVectorDatabase[{{1, 2, 3} -> <|"tag1" -> "A", "tag2" -> 42|>, {4, 5, 6} -> <|"tag1" -> "B", "tag2" -> 1234|>}]Specify data and metadata separately:
CreateVectorDatabase[{{1, 2, 3}, {4, 5, 6}} -> {<|"tag1" -> "A", "tag2" -> 42|>, <|"tag1" -> "B", "tag2" -> 1234|>}]Options (10)
DistanceFunction (1)
Specify a custom distance function for the database:
CreateVectorDatabase[DistanceFunction -> CosineDistance]By default, EuclideanDistance is used:
CreateVectorDatabase[]["DistanceFunction"]FeatureExtractor (1)
Only vectors can be stored in the database; specify a FeatureExtractor that can extract image features:
db = CreateVectorDatabase[{[image], [image], [image], [image], [image], [image]}, FeatureExtractor -> "ImageFeatures"]Search for the closest image to a given one:
VectorDatabaseSearch[db, [image]]GeneratedAssetLocation (3)
Specify a custom location to store the database:
CreateVectorDatabase["myDB", GeneratedAssetLocation -> "CloudObject"]%["Location"]By default, the database is stored in a local object:
CreateVectorDatabase[]["Location"]Store the vector database in a file:
file = File[FileNameJoin[{$TemporaryDirectory, "testfile"}]]CreateVectorDatabase["myDB", GeneratedAssetLocation -> file]%["Location"]Recreate the database from the file reference:
VectorDatabaseObject[File["/private/var/folders/05/v_ct9frn7zv4vy6f2q18y2r80000gn/T/testfile"]]OverwriteTarget (2)
The database's automatic location is determined by its name:
CreateVectorDatabase["myDB"]With default OverwriteTargetAutomatic, a new database name is generated to avoid collisions:
CreateVectorDatabase["myDB"]To force overwriting, use OverwriteTargetTrue:
CreateVectorDatabase["myDB", OverwriteTarget -> True]Use OverwriteTargetFalse to perform a strict check:
CreateVectorDatabase["myDB", OverwriteTarget -> False]OverwriteTargetFalse will also prevent reusing the same database name in a different location:
CreateVectorDatabase["myDB", OverwriteTarget -> False, GeneratedAssetLocation -> File["myDBfile"]]CreateFile@File["myDBfile"]By default, existing files are not overwritten:
CreateVectorDatabase["myDB", GeneratedAssetLocation -> File["myDBfile"]]Use OverwriteTargetTrue to overwrite the existing file:
CreateVectorDatabase["myDB", GeneratedAssetLocation -> File["myDBfile"], OverwriteTarget -> True]WorkingPrecision (3)
Specify a custom working precision for the distance computation:
CreateVectorDatabase[{{1, 2, 3}}, WorkingPrecision -> "Real32"]By default, the precision is inferred from the input data:
CreateVectorDatabase[{{1, 2, 3}}]["WorkingPrecision"]Specify a precision for an empty database:
db = CreateVectorDatabase[WorkingPrecision -> "Real32"];Newly added vectors are clipped and/or rounded to fit into the given precision:
AddToVectorDatabase[db, {{1, 2, 10 ^ 100}}]["Vectors"]//NormalAn empty database is created without an explicit working precision:
db = CreateVectorDatabase[];
db["WorkingPrecision"]The value is resolved when data is added to the database:
AddToVectorDatabase[db, {{1, 2, 3}}]["WorkingPrecision"]Properties & Relations (1)
Possible Issues (4)
Only one-dimensional arrays can be stored in the database:
CreateVectorDatabase[{(| | |
| - | - |
| 1 | 2 |
| 3 | 4 |), (| | |
| - | - |
| 5 | 6 |
| 7 | 8 |)}]All arrays in the database should have the same size:
CreateVectorDatabase[{{1, 2, 3}, {1, 2}}]CreateVectorDatabase["DemoDB"]A new database with the same name specification will be created with an incrementing suffix:
Table[CreateVectorDatabase["DemoDB"]["ID"], 5]Use DeleteObject to remove an incorrectly generated VectorDatabaseObject:
DeleteObject[VectorDatabaseObjects["DemoDB*"]]Now the name is available again:
CreateVectorDatabase["DemoDB"]Alternatively, use the option OverwriteTargetTrue to overwrite the old database:
CreateVectorDatabase["DemoDB", OverwriteTarget -> True]OverwriteTarget -> False will issue an error rather than adding an incrementing number:
CreateVectorDatabase["DemoDB", OverwriteTarget -> False]Create a database at a specific location:
db = CreateVectorDatabase["myDB", GeneratedAssetLocation -> File["myDBfile"]]A database with the same name in a new location will be created with an incrementing suffix:
CreateVectorDatabase["myDB", GeneratedAssetLocation -> File["myDBfile2"]]Delete the original database to free the name:
DeleteObject[db]Now the name is available again:
CreateVectorDatabase["myDB", GeneratedAssetLocation -> File["myDBfile2"], OverwriteTarget -> True]db = CreateVectorDatabase[RandomReal[1, {1000, 10}], GeneratedAssetLocation -> None]db[[1]]PersistentObject["SemanticSearch`Storage`VectorDB-e75090c3-01ff-4318-ada5-38536495b10b", "KernelSession"]["Value"]Related Guides
History
Text
Wolfram Research (2024), CreateVectorDatabase, Wolfram Language function, https://reference.wolfram.com/language/ref/CreateVectorDatabase.html.
CMS
Wolfram Language. 2024. "CreateVectorDatabase." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/CreateVectorDatabase.html.
APA
Wolfram Language. (2024). CreateVectorDatabase. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/CreateVectorDatabase.html
BibTeX
@misc{reference.wolfram_2026_createvectordatabase, author="Wolfram Research", title="{CreateVectorDatabase}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/CreateVectorDatabase.html}", note=[Accessed: 15-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_createvectordatabase, organization={Wolfram Research}, title={CreateVectorDatabase}, year={2024}, url={https://reference.wolfram.com/language/ref/CreateVectorDatabase.html}, note=[Accessed: 15-June-2026]}