VectorDatabaseSearch[db,vector]
gives the element of the vector database db nearest to vector.
VectorDatabaseSearch[db,vector,n]
gives the n nearest vectors.
VectorDatabaseSearch[db,vector,prop]
returns the property prop associated with the result.
VectorDatabaseSearch[db,vector,prop,n]
returns the property prop associated with the n nearest vectors.
VectorDatabaseSearch[db,vectorf,…]
filters the results using the function f.
VectorDatabaseSearch
VectorDatabaseSearch[db,vector]
gives the element of the vector database db nearest to vector.
VectorDatabaseSearch[db,vector,n]
gives the n nearest vectors.
VectorDatabaseSearch[db,vector,prop]
returns the property prop associated with the result.
VectorDatabaseSearch[db,vector,prop,n]
returns the property prop associated with the n nearest vectors.
VectorDatabaseSearch[db,vectorf,…]
filters the results using the function f.
Details
- VectorDatabaseSearch performs a search on the vector database using a query to find and retrieve similar items.
- This function is used for tasks like finding similar documents, images or products via their vector representation, enhancing capabilities in recommendation systems and content discovery.
- Valid db specifications are:
-
"name" a string matching a named vector database VectorDatabaseObject[…] a valid VectorDatabaseObject - The vector must have the same length as the vector stored in the database. »
- The input to the function f is the same annotation specified when the database was created. »
- Possible property values prop include:
-
"Distance" the distance from vector "Element" the vector found to be nearest "Index" the element position in the database "Metadata" metadata associated with the element "Metadata"tag a specific metadata value "Metadata"->{"tag1",…} multiple metadata values {prop1,…} a list of properties All a Dataset with all the properties
Examples
open all close allBasic Examples (1)
Scope (4)
Initialize a new vector database with a list of vectors:
db = CreateVectorDatabase[RandomReal[{-1, 1}, {10, 2}], "myDB"]Find the first nearest vector:
VectorDatabaseSearch[db, {.4, -.1}]Find the list of the first three nearest vectors:
VectorDatabaseSearch[db, {.4, -.1}, 3]Find the vectors together with their distance:
VectorDatabaseSearch[db, {.4, -.1}, {"Element", "Distance"}, 3]List all the properties of each result:
VectorDatabaseSearch[db, {.4, -.1}, All, 3]Create a vector database with labeled arrays:
db = CreateVectorDatabase[{{0.461805, -0.124455} -> "B", {0.499963, 0.175775} -> "B", {-0.3618, 0.234523} -> "B", {0.386341, -0.817076} -> "A", {0.618673, 0.564247} -> "A", {0.858462, -0.415309} -> "A", {-0.973365, 0.141012} -> "A", {0.728871, 0.593306} -> "A", {-0.810667, 0.833625} -> "B", {-0.67246, -0.674525} -> "B"}, "myDB"]The label is automatically returned when searching:
VectorDatabaseSearch[db, {.4, -.1}]VectorDatabaseSearch[db, {.4, -.1}, "Element"]VectorDatabaseSearch[db, {.4, -.1}, "Metadata"]Filter the result to only contain vectors with a specific label:
VectorDatabaseSearch[db, {.4, -.1} -> MatchQ["A"], 3]Create a vector database with metadata associated to each vector:
db = CreateVectorDatabase[{{1, 2} -> <|"Value" -> 1|>, {-3, 5} -> <|"Value" -> 2|>, {4, -3} -> <|"Value" -> 3|>, {5, 1} -> <|"Value" -> 4|>}, "myDB"]Search for the two nearest vectors:
VectorDatabaseSearch[db, {.4, -.1}, 2]Return only vectors matching a specified filter:
VectorDatabaseSearch[db, {.4, -.1} -> Function[#Value > 2], 2]Create a vector database with multiple metadata elements associated to each vector:
db = CreateVectorDatabase[{{1, 2} -> <|"Value" -> 1, "Minimum" -> 1|>, {-3, 5} -> <|"Value" -> 2, "Minimum" -> -3|>, {4, -3} -> <|"Value" -> 3, "Minimum" -> -3|>, {5, 1} -> <|"Value" -> 4, "Minimum" -> 1|>}, "myDB"]All metadata is returned when searching:
VectorDatabaseSearch[db, {.4, -.1}, 2]Return only the specified metadata:
VectorDatabaseSearch[db, {.4, -.1}, "Metadata" -> "Minimum", 2]Return multiple metadata elements with labels:
VectorDatabaseSearch[db, {.4, -.1}, "Metadata" -> {"Value", "Minimum"}, 2]Return metadata elements alongside other properties:
VectorDatabaseSearch[db, {.4, -.1}, { "Metadata" -> {"Value"}, "Distance"}, 2]Filter on multiple metadata elements:
VectorDatabaseSearch[db, {.4, -.1} -> Function[#Value > 2 && #Minimum < 1], { "Metadata" -> {"Value"}, "Distance"}]Applications (1)
Image Search (1)
Assemble a collection of images:
images = {[image], [image], [image], [image], [image], [image]};Label each image with a class:
labels = {"squirrel", "squirrel", "squirrel", "monkey", "monkey", "monkey"}Define a feature extraction function that uses a neural network to compute vector features:
fe = NetDrop[NetModel["YOLO V8 Classify Trained on ImageNet Competition Data"], -2]Compute the feature vector for each image:
vectors = fe[images];
Short[vectors]Create a vector database with the labeled vectors:
CreateVectorDatabase[vectors -> labels, "Squirrels&Monkeys"]Search for similar images in the database:
VectorDatabaseSearch["Squirrels&Monkeys", fe[[image]], 6]Properties & Relations (2)
The distance function property is defined when creating the database:
db = CreateVectorDatabase[{{3, 3}, {1, 2}}, DistanceFunction -> CosineDistance]Search the nearest vector using the specified distance:
VectorDatabaseSearch[db, {1, 1}]Create a database with annotated vectors:
db = CreateVectorDatabase[{{-2, 3} -> <|"Tag" -> "A", "Time" -> TimeObject[{6, 8, 11.9769}, "Instant"]|>, {-4, -5} -> <|"Tag" -> "B", "Time" -> TimeObject[{5, 24, 5.54875}, "Instant"]|>, {-2, 5} -> <|"Tag" -> "A", "Time" -> TimeObject[{1, 19, 42.8523}, "Instant"]|>}]The filter function input is the annotation association:
VectorDatabaseSearch[db, {1, 1} -> Echo]Possible Issues (2)
Create a database with 2D vectors:
db = CreateVectorDatabase[{{3., 3.}, {1., 2.}}]It is not possible to search using query vectors of different lengths:
VectorDatabaseSearch[db, {1., 2., 3.}]Create a vector database with multiple metadata elements associated to each vector:
db = CreateVectorDatabase[{{1, 2} -> <|"Value" -> 1, "Minimum" -> 1|>, {-3, 5} -> <|"Value" -> 2, "Minimum" -> -3|>, {4, -3} -> <|"Value" -> 3, "Minimum" -> -3|>, {5, 1} -> <|"Value" -> 4, "Minimum" -> 1|>}, "myDB"]Only elements that fit the specified filters will be returned, even if this is less than the number requested:
VectorDatabaseSearch[db, {.4, -.1} -> (#Value > 2 && #Minimum < 1&), { "Metadata" -> {"Value"}, "Distance"}, 4]Related Guides
Text
Wolfram Research (2024), VectorDatabaseSearch, Wolfram Language function, https://reference.wolfram.com/language/ref/VectorDatabaseSearch.html (updated 2025).
CMS
Wolfram Language. 2024. "VectorDatabaseSearch." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/VectorDatabaseSearch.html.
APA
Wolfram Language. (2024). VectorDatabaseSearch. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/VectorDatabaseSearch.html
BibTeX
@misc{reference.wolfram_2026_vectordatabasesearch, author="Wolfram Research", title="{VectorDatabaseSearch}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/VectorDatabaseSearch.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_vectordatabasesearch, organization={Wolfram Research}, title={VectorDatabaseSearch}, year={2025}, url={https://reference.wolfram.com/language/ref/VectorDatabaseSearch.html}, note=[Accessed: 13-June-2026]}