Querying the collection
The code in this section executes a query against the Chroma vector store using its integrated semantic search functionality. It queries the vector representations of all the vectors in the Chroma collection questions in the initial dataset:
dataset["question"][:nbq].
The query requests one most relevant or similar document for each question with n_results=1
, which you can modify if you wish.
Each question text is converted into a vector. Then, Chroma runs a vector similarity search by comparing the embedded vectors against our database of document vectors to find the closest match based on vector similarity:
import time
start_time = time.time() # Start timing before the request
# number of retrievals to write
results = collection.query(
query_texts=df["question"][:nb],
n_results=1)
response_time = time.time() - start_time # Measure response time
print(f"Response Time: {response_time:.2f} seconds") ...