Knowledge-base retrieval
Retrieve relevant passages from an internal knowledge base before generating an answer.
AI & ML · Const
Semantic search uses embeddings to find semantically relevant chunks in indexed data, including matches with few or no shared keywords. OpenAI's Retrieval API performs this search over vector stores.
Semantic search represents a natural-language query and stored content as embeddings, then ranks stored chunks by semantic similarity. OpenAI's Retrieval API performs this search over vector stores and returns matching chunks, similarity scores, and their source files; query rewriting can optionally improve search queries.
client.vector_stores.search(vector_store_id, query, rewrite_query=false)| Name | Type | Description |
|---|---|---|
vector_store_id | string | Identifier of the vector store containing the indexed data. |
query | string | Natural-language text to search for. |
rewrite_query | boolean | Optional setting that rewrites the query for improved performance. |
A list of results containing relevant chunks, similarity scores, and the file of origin.
from openai import OpenAI
client = OpenAI()
results = client.vector_stores.search(
vector_store_id="vs_123",
query="How do I reset my password?",
)
for result in results.data:
print(result.filename, result.score)
for content in result.content:
print(content.text)Searches a vector store with a natural-language query and prints matching files, similarity scores, and content chunks.
Retrieve relevant passages from an internal knowledge base before generating an answer.
Find documents matching a user's intent when exact keywords differ.
Locate semantically related code or text across an indexed corpus.
vector storesembeddingsRetrieval APIquery rewritingfile search