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,n]

returns the property prop associated with the result.

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"taga specific metadata value
    "Metadata"->{"tag1",}multiple metadata values
    {prop1,}a list of properties
    Alla Dataset with all the properties

Examples

open allclose all

Basic Examples  (1)

Initialize a new vector database with a list of vectors:

Perform a search operation:

Scope  (4)

Initialize a new vector database with a list of vectors:

Find the first nearest vector:

Find the list of the first three nearest vectors:

Find the vectors together with their distance:

List all the properties of each result:

Create a vector database with labeled arrays:

The label is automatically returned when searching:

Return the vector instead:

Return the label explicitly:

Filter the result to only contain vectors with a specific label:

Create a vector database with metadata associated to each vector:

Search for the two nearest vectors:

Return only vectors matching a specified filter:

Create a vector database with multiple metadata elements associated to each vector:

All metadata is returned when searching:

Return only the specified metadata:

Return multiple metadata elements with labels:

Return metadata elements alongside other properties:

Filter on multiple metadata elements:

Applications  (1)

Image Search  (1)

Assemble a collection of images:

Label each image with a class:

Define a feature extraction function that uses a neural network to compute vector features:

Compute the feature vector for each image:

Create a vector database with the labeled vectors:

Search for similar images in the database:

Properties & Relations  (2)

The distance function property is defined when creating the database:

Search the nearest vector using the specified distance:

Create a database with annotated vectors:

The filter function input is the annotation association:

Possible Issues  (2)

Create a database with 2D vectors:

It is not possible to search using query vectors of different lengths:

Create a vector database with multiple metadata elements associated to each vector:

Only elements that fit the specified filters will be returned, even if this is less than the number requested:

Wolfram Research (2024), VectorDatabaseSearch, Wolfram Language function, https://reference.wolfram.com/language/ref/VectorDatabaseSearch.html (updated 2025).

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_2024_vectordatabasesearch, author="Wolfram Research", title="{VectorDatabaseSearch}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/VectorDatabaseSearch.html}", note=[Accessed: 21-January-2025 ]}

BibLaTeX

@online{reference.wolfram_2024_vectordatabasesearch, organization={Wolfram Research}, title={VectorDatabaseSearch}, year={2025}, url={https://reference.wolfram.com/language/ref/VectorDatabaseSearch.html}, note=[Accessed: 21-January-2025 ]}