query-vector-db
This agent enables submitting queries to a vector datasource (like Pinecone or AstraDB) and outputting the results.
Example
Follow the Pinecone Quickstart docs to create your Pinecone API key, environment, vector index name, and project name, and add them to your secrets.yaml file. These values are required.
Specify a datasource in configuration.yaml:
Reference the "vector-database" datasource and submit a query using input message values in pipeline.yaml:
The query language depends on the underlying vector database. For example, Pinecone uses a JSON query language. See the Pinecone Query Language docs for more information.
Please refer to the documentation of the vector database you are using for more information on how to write queries:
Automatically repeating the query over a list of inputs
It is possible to perform the same computation over a list of inputs - for example, a list of questions. You can take the Flare pattern as an example.
In the example below we use the 'loop-over' capability to query the database for each document in the list of documents to retrieve.
When you use "loop-over", the agent executes for each element in a list instead of operating on the whole message. Use "record.xxx" to refer to the current element in the list.
The snippet above computes the embeddings for each element in the list "documents_to_retrieve". The list is expected to be a struct like this:
The agent then adds all the results to a new field named "retrieved_documents" in the message.
After running the agent the contents of the list are:
Topics
Input
Output
Configuration
datasource
string
A reference to the datasource name declared in resources.datasources of the configuration.yaml manifest.
query
string
The query statement to run. Each placeholder “?” will be replaced with fields value in order.
Example:
fields
string[]
A collection of field values. Each value will be used in order to replace placeholders in the query (do not include mustache brackets, this is not a templated value).
Example collection:
“value.embeddings”
output-field
string
The name of an additional field to be added to message data containing query result (do not include mustache brackets, this is not a templated value).
Provide in the form: “value.<field-name>”
What's next?
For more on vector databases, see Vector Databases.
For more on the datasource resource, see Datasource.
Last updated