The context endpoint lets you intelligently search all propietary datasets and the web for the most relevant information for you AI agents and applications.
By default, it automatically chooses both propietary datasets and the web, to find the most relevant results for your query.
Python TypeScript cURL
Copy from valyu import Valyu
valyu = Valyu()
query = "What is positional encoding in transformers"
response = valyu.context(
query=query,
search_type="both",
num_query=5,
num_results=3,
max_price=10
)
print(response)
Copy import { Valyu } from 'valyu';
const valyu = new Valyu("<api_key>");
const response = await valyu.context({
query: "Tell me about ancient civilizations",
searchType: "both",
numQuery: 5,
numResults: 3,
maxPrice: 10
});
Copy curl -X POST "https://api.valyu.network/v1/knowledge" \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-d '{
"query": "What is multihead attention?",
"search_type": "both",
"num_query": 10,
"num_results": 10,
"max_price": 30.0
}'
If you only want to query a specific set of indexes, you can pass the index names as a parameter.
Python TypeScript cURL
Copy valyu = Valyu()
query = "What is positional encoding in transformers"
response = valyu.context(
query=query,
search_type="proprietary",
data_sources=["valyu/valyu-arxiv","valyu/valyu-wikipedia"],
num_query=5,
num_results=3,
max_price=10
)
print(response)
Copy import { Valyu } from 'valyu';
const valyu = new Valyu("<api_key>");
const response = await valyu.context({
query: "Tell me about ancient civilizations",
searchType: "proprietary",
dataSources: ["valyu/valyu-arxiv","valyu/valyu-wikipedia"],
numQuery: 5,
numResults: 3,
maxPrice: 10
});
Copy curl -X POST "https://api.valyu.network/v1/knowledge" \
-H "x-api-key: YOUR_API_KEY" \
-d '{
"query": "What is multihead attention?",
"search_type": "proprietary",
"data_sources": ["valyu/valyu-arxiv","valyu/valyu-wikipedia"],
"num_query": 10,
"num_results": 10,
"max_price": 30.0
}'
Response
200 206 400
Copy {
"success": true,
"query": "What is multihead attention?",
"results": [
{
"title": "Understanding Multihead Attention",
"url": "https://example.com/multihead-attention",
"content": "Multihead attention is a mechanism...",
"description": "A deep dive into multihead attention in transformers.",
"source": "proprietary",
"price": 5.0, // Price in PCM
"length": 2500, // Content length in characters
"orgname": "AI Research Inc.",
"relevance_score": 0.95, // Relevance score (0-1)
"source_type": ""
}
],
"results_by_source": {
"proprietary": 7,
"web": 3
},
"total_deduction_pcm": 15.0,
"total_deduction_dollars": 0.50,
"total_characters": 15000
}
Copy {
"success": true,
"query": "What is multihead attention?",
"error": "Web results retrieval failed.",
"results": [
{
"title": "Understanding Multihead Attention",
"url": "https://example.com/multihead-attention",
"content": "Multihead attention is a mechanism...",
"description": "A deep dive into multihead attention in transformers.",
"source": "Organisation index",
"price": 5.0,
"length": 2500,
"orgname": "AI Research Inc.",
"relevance_score": 0.95,
"source_type": "proprietary"
}
],
"results_by_source": {
"proprietary": 7,
"web": 0
},
"total_deduction_pcm": 15.0,
"total_deduction_dollars": 0.50,
"total_characters": 15000
}
Copy {
"success": false,
"error": "Error Message"
}
Field Descriptions
Request Fields
query (string, required) : The question or topic the user wants information on.
search_type (string, required) : Defines whether to search in "proprietary", "web", or "both" sources.
data_sources (string, optional) : Choose which indexes to only query from.
num_query (integer, default: 10) : Number of query variations generated.
num_results (integer, default: 10) : Maximum number of results returned.
max_price (float, default: unlimited) : The maximum allowed price per content in PCM (per thousand queries).
Response Fields
success (boolean) : Indicates whether the request was successful.
query (string) : Echoes the input query.
error (string, optional) : Describes the issue if only a partial response is available.
results (array) : List of retrieved documents.
title (string) : Title of the content.
url (string) : Link to the content.
content (string) : Extracted text from the source.
description (string, optional) : Brief description of the content.
source (string) : Which index is the data from.
price (float) : Cost of accessing the content in PCM.
length (integer) : Character count of the content.
orgname (string) : Organization providing the content.
relevance_score (float) : Score between 0 and 1 indicating relevance.
source_type (string) : Is the content proprietary or from the web.
results_by_source (object) : Count of results by source type.
proprietary (integer) : Number of proprietary results.
web (integer) : Number of web results.
total_deduction_pcm (float) : Total cost in PCM for retrieved proprietary content.
total_deduction_dollars (float) : Equivalent cost in dollars.
total_characters (integer) : Total number of characters retrieved across all results.