AI-API - Summarize Context

Vector Embedding API

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:

  1. Retrieve — run a search on your index (for best results use hybrid search via the Solr {!hybrid} parser or the embed_and_search API endpoint) and take your top 3–4 results. embed_and_search runs 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).
  2. Summarize — concatenate the title, description and text of those results and send them to ai_summary as 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.

  1. GET or POST https://api.opensolr.com/solr_manager/api/ai_summary
  2. Parameters:
    1. ​email - Required - your Opensolr registration email address
    2. api_key - Required - your Opensolr api_key
    3. ​index_name - Required - must be a valid Opensolr Index that belongs to you.
    4. ​context - Required - the text the LLM will read: typically the concatenated title + description + text of your top search results (3–4 results, up to ~1500 words each, works well), or any text of your own.
    5. ​query - Optional - the user's question. It is referenced by the instruction so the answer stays focused on what was asked.
    6. ​instruction - Optional - The instruction to send to the AI LLM. Defaults to: "Answer the query in plain English language, or translate into English, and summarize all the key points about the dates, people, events, places, or other important things that you find in the context below. Focus on the main ideas." You can also use instructions such as: "Extract a list of people names... " or "Translated this content to ... LANG", etc...

    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

    # context = title + description + text of the results from step 1
    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 "query=What is hybrid search?" \
      -d "context=Hybrid Search - Combine keyword and vector search - Hybrid search fuses BM25 keyword scores with kNN vector similarity per document..." \
      -d "instruction=Read the context below and formulate a clear, concise answer to the query."
    

    PHP 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 + [
        'query'       => $question,
        'context'     => $context,
        'instruction' => 'Read the context below and formulate a clear, concise answer to the query.',
    ]));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    echo trim(curl_exec($ch));
    curl_close($ch);
    

    Py 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,
            "query": question,
            "context": context,
            "instruction": "Read the context below and formulate a clear, concise answer to the query.",
        },
    )
    print(resp.text.strip())
    
Custom Plans Available

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.