Chaining vector searches across shared key relationships

I’m thinking of a situation where I have a database with a collection of movies and another of directors, linked by shared keys. Instead of storing the director’s name against the document for a particular movie, we store the id of a director document in the movie document. A movie document might look like:

{
 id: #movieid
 title: Vertigo
 director: #directorid
}

and the director document might look like:

{
  id: #directorid
  name: Hitchcock
}

In this case how would I configure my indexing so that a vector search recognised a director ‘belongs’ to a movie?

How would I show the query that had taken place?

Here you could use $lookup subsequent to the vector search to link directorID from the first collection with the name from the second. Here is an example of how $lookup can be used in a pipeline where it looks up documents from the same page within the same collection.

Modeling foreign key relationships like this with $lookup following $vectorSearch is a common pattern we’ve seen- let me know if this makes sense or if you have any other questions!

1 Like