Query Relevant Chunks
Description
Query a knowledge base for text chunks that are most semantically relevant to the query.
Details
Given a query expressed as an embedding, this API runs a similarity search amongst the embeddings indexed in the knowledge base to find the most relevant chunk embeddings. To use this API, specify the knowledge_base_id
of the knowledge base you want to query, pass in the natural language query
that you want to search for, specify the value top_k
, which is the number of similar chunks that will be returned, and specify whether you want the returned chunks to include_embeddings
.
Similarity search is used to efficiently find, retrieve, and rank chunks based on their similarity to a given query, which is also expressed as an embedding. Similarity scores ( using the cosine similarity metric) are calculated between each chunk embedding and the embedded query, and the chunks are ranked based on similarity score. The top-ranked chunks are returned as the query results.
We are using the Hierarchical Navigable Small World (HNSW) algorithm to perform a k nearest neighbors search in the vector space. This algorithm returns an estimate of the best k nearest neighbors and is optimized for datasets with hundreds of thousands of vectors. You can read more about the specifics of this algorithm here.
Backwards Compatibility
V2 and V1 Knowledge Bases are entirely separate and not backwards compatible. Users who have existing V1 knowledge bases will need to migrate their data to V2 knowledge bases.
Authorizations
Path Parameters
Body
The natural language query to be answered by referencing the data ingested into the knowledge base
Number of chunks to return. Must be greater than 0 if specified. If not specified, all chunks will be returned.
0 < x < 10000
Whether or not to include the embeddings for each chunk
Optional filter by metadata fields, encoded as a JSON object
Optional wildcard filter for fields. Only fields that are part of the metadata will be accepted.
Enable or disable verbose logging
Response
An ordered list of the k most similar chunks and their similarity scores from most to least similar
Timestamp at which the query was begun by the server.
Timestamp at which the query was completed by the server.
query request ID for verbose logging