Opensolr AI-Hints - Demo Implementation
The Opensolr AI-Hints API, is free to use as part of your Opensolr Account.
The Opensolr AI-Hints LLM generates a summary, or answers a question, from the context you provide. This is the same API that powers the AI answers on our hosted search pages.
A number of other instructions can be passed on to this API, for NER, translation, and other capabilities.
The RAG pattern: search first, then summarize
Grounded AI answers work in two steps:
- Retrieve — run a search on your index (for best results use hybrid search via the Solr
{!hybrid}parser or theembed_and_searchAPI endpoint) and take your top 3–4 results.embed_and_searchruns the platform's tuned hybrid pipeline: your index's saved Search Tuning (Control Panel → Index Settings → Search Tuning) applies automatically, and you can override any knob per request with these optional parameters:fw_title,fw_description,fw_uri,fw_text,fw_text_t,lexical_weight,vector_weight,vector_topk(10–1000),search_mode(union / keywords_required / meaning_required / intersection),quality_boost,min_score,freshness_boost,mm(flexible / balanced / strict, or raw Solr mm syntax). - Summarize — concatenate the
title,descriptionandtextof those results and send them toai_summaryas the context parameter, together with the user's question as query.
This keeps you in full control of retrieval — your own filters, boosts and tuning decide what the LLM reads.
- GET or POST https://api.opensolr.com/solr_manager/api/ai_summary
- Parameters:
- email - Required - your Opensolr registration email address
- api_key - Required - your Opensolr api_key
- index_name - Required - must be a valid Opensolr Index that belongs to you.
- instruction - Required - the complete prompt, and the only field that shapes the answer. What you write here is exactly what the model reads, byte for byte: nothing reorders it, relabels it, appends to it or shortens it. Up to 100,000 characters. Typically your question, then the concatenated
title+description+textof your top 3–4 search results under aCONTENT:label, plus any rules the answer should follow. - query - Deprecated - still accepted so existing integrations keep working. When present it is appended to your instruction under a
QUERY:label. Put the question insideinstructioninstead, where you decide where it sits. - context - Deprecated - still accepted so existing integrations keep working. When present it is appended to your instruction under a
CONTENT:label. Put the content insideinstructioninstead.
Full Working Examples
cURL — Step 1: retrieve with hybrid search
curl -X POST https://api.opensolr.com/solr_manager/api/embed_and_search \ -d "email=your@email.com" \ -d "api_key=YOUR_API_KEY" \ -d "index_name=your_index" \ -d "q=What is hybrid search?" \ -d "rows=4" \ -d "in=all" \ -d "fresh=no" \ -d "search_mode=keywords_required" \ -d "mm=strict"
The last two lines are optional per-request Search Tuning overrides — without them, your index's saved Search Tuning (or the platform defaults) applies.
cURL — Step 2: summarize the results
# The instruction is the whole prompt: your question, your rules, and the content you # retrieved in step 1. Nothing is added or rewritten between here and the model. curl -X POST https://api.opensolr.com/solr_manager/api/ai_summary \ -d "email=your@email.com" \ -d "api_key=YOUR_API_KEY" \ -d "index_name=your_index" \ -d "instruction=Answer this query using only the content below: What is hybrid search? Begin with the answer itself. No preamble, no restating the query. Use only what the content states. CONTENT: Hybrid Search - Combine keyword and vector search - Hybrid search fuses BM25 keyword scores with kNN vector similarity per document..."
PHP
<?php $auth = ['email' => 'your@email.com', 'api_key' => 'YOUR_API_KEY', 'index_name' => 'your_index']; $question = 'What is hybrid search?'; // Step 1: hybrid retrieval $ch = curl_init('https://api.opensolr.com/solr_manager/api/embed_and_search'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($auth + [ 'q' => $question, 'rows' => 4, 'in' => 'all', 'fresh' => 'no', ])); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $docs = json_decode(curl_exec($ch), true)['results']['docs'] ?? []; curl_close($ch); // Step 2: build the context from the top results and summarize $context = ''; foreach (array_slice($docs, 0, 4) as $doc) { $context .= ($doc['title'] ?? '') . ' - ' . ($doc['description'] ?? '') . ' - ' . implode(' ', array_slice(explode(' ', $doc['text'] ?? ''), 0, 1500)) . ' - '; } $ch = curl_init('https://api.opensolr.com/solr_manager/api/ai_summary'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($auth + [ 'instruction' => "Answer this query using only the content below: {$question}\n" . "Begin with the answer itself. No preamble, no restating the query.\n" . "Use only what the content states.\n\nCONTENT:\n" . $context, ])); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); echo trim(curl_exec($ch)); curl_close($ch);
Python
import requests AUTH = {"email": "your@email.com", "api_key": "YOUR_API_KEY", "index_name": "your_index"} question = "What is hybrid search?" # Step 1: hybrid retrieval resp = requests.post( "https://api.opensolr.com/solr_manager/api/embed_and_search", data={**AUTH, "q": question, "rows": 4, "in": "all", "fresh": "no"}, ) docs = resp.json().get("results", {}).get("docs", []) # Step 2: build the context from the top results and summarize context = "" for doc in docs[:4]: words = " ".join(str(doc.get("text", "")).split()[:1500]) context += f"{doc.get('title', '')} - {doc.get('description', '')} - {words} - " resp = requests.post( "https://api.opensolr.com/solr_manager/api/ai_summary", data={ **AUTH, "instruction": ( f"Answer this query using only the content below: {question}\n" "Begin with the answer itself. No preamble, no restating the query.\n" "Use only what the content states.\n\nCONTENT:\n" + context ), }, ) print(resp.text.strip())
This is a premium feature available on custom plans tailored to your needs and budget. For small websites, we can even provide these features for free after validating your use case. Contact us at support@opensolr.com to discuss your requirements.