Using Vector Indexes
Once you've got an instance of a Vector Index, either through self.vector_index on a VectorIndexedMixin model, or through your own custom index, you can run a few useful operations on the index:
Natural language question/answers
The query method can be used to ask natural language questions:
index.query("What is the airspeed velocity of an unladen swallow?")
QueryResponse(
response="What do you mean? An African or a European swallow?", sources=[MyPage(1)]
)
Behind the scenes, this:
- Converts the query in to an embedding
- Uses the vector backend to find content in the same index that is similar
- Merges all the matched content in to a single 'context' string
- Passes the 'context' string along with the original query to the AI backend.
- Returns a
QueryResponsecontaining theresponsefrom the AI backend, andsources, a list of objects that were used as context.
Getting similar content
The find_similar index method can be used to find model instances that are similar to another instance:
This works by:
- Generating (or retrieving existing) embeddings for the instance
- Using the vector database to find matching embeddings
- Returning the original model instances that were used to generate these matching embeddings
Searching content
The search index method can be used to use natural language to search content in the index.
This is similar to querying content, but it only returns content matches without a natural language response.