AI-API - Summarize Context

AI API: Vectors, Images & LLM

ai_summary writes an answer, or a summary, from the content you give it, with the language model that runs on Opensolr's own servers. You decide everything the model reads: your question, your rules and the content, usually the best results of a search on your index.

01 · The request

https://api.opensolr.com/solr_manager/api/ai_summary

GET or POST, as form fields or as a JSON body. Use POST: the instruction is usually long.

ParameterRequiredWhat it is
emailyesThe email of your Opensolr account.
api_keyyesYour API key, or a scoped key that allows ai_summary: Authentication and keys.
index_nameyesOne of your indexes. It decides whose AI allowance is used.
instructionyesThe whole prompt. The model reads exactly what you send: nothing is added, reordered or shortened. Typically your question, how the answer should look, then the title, description and text of your best results under a CONTENT: label.
streamnoThe answer is sent word by word as it is written. stream=no sends it whole, when it is finished.
answer_formatnopicks: the answer as JSON, one sentence plus the documents that answer it (below).
queryno, olderStill accepted: added to the end of the instruction under a QUERY: label. Put the question inside instruction instead.
contextno, olderStill accepted: added under a CONTENT: label. Put the content inside instruction instead.

02 · A good instruction

Answer the question using only the content below: How do I reset my password?
Begin with the answer itself. Use only what the content states.

CONTENT:
[1] Reset your password - Account help - Open Account, click Reset password ...
[2] Sign-in problems - Account help - If the reset email does not arrive ...

Put in the content of your 3 or 4 best results.

The model knows today's date (UTC), so a question about "this year" or "last week" makes sense to it.

The full search-then-answer code, in PHP and Python: RAG in two calls.

03 · The answer

Plain text, sent word by word as it is written. With answer_format=picks it is JSON:

{
  "answer": "Open Account and click Reset password; the link arrives by email.",
  "items": [
    {"doc": 1, "fact": "Reset password is in the Account menu."},
    {"doc": 2, "fact": "The reset email can take a few minutes."}
  ]
}

answer is one sentence, and each item names a document by number with the fact it gives. Number your documents in the instruction, as above, so the numbers point back to them.

AnswerWhy
VECTOR_NOT_ALLOWED (HTTP 403)AI is switched off on the plan of the account that owns the index.
ERROR_AI_MONTHLY_QUOTA_EXCEEDED (HTTP 429)This month's AI allowance is used up.
ERROR_NOT_CORE_OWNER (HTTP 404)The index is not one your account can use.

Authentication, rate limits and a wrong host answer as described in API errors.

04 · What it uses from your plan

Each answer written counts as one AI request of the account that owns the index, and an answer that fails is not counted.

The same instruction sent again for the same index on the same day (UTC) gets the same answer from cache, for free.

Every plan includes a monthly AI allowance of 500 AI requests; see pricing and API Quota.

05 · Example

# prompt.txt holds the whole instruction: question, rules, content
curl -s https://api.opensolr.com/solr_manager/api/ai_summary \
  --data-urlencode "email=YOUR_EMAIL" \
  --data-urlencode "api_key=YOUR_API_KEY" \
  --data-urlencode "index_name=YOUR_INDEX" \
  --data-urlencode "instruction@prompt.txt"
import requests

instruction = open("prompt.txt", encoding="utf-8").read()

with requests.post("https://api.opensolr.com/solr_manager/api/ai_summary", data={
    "email": "YOUR_EMAIL",
    "api_key": "YOUR_API_KEY",
    "index_name": "YOUR_INDEX",
    "instruction": instruction,
}, stream=True, timeout=300) as r:
    for chunk in r.iter_content(chunk_size=None, decode_unicode=True):
        print(chunk, end="", flush=True)

06 · Related

Find the content to answer from: embed_and_search.

The same answers, ready made: AI Hints on the hosted search page and the chat bot on your site.

All the answer and chat calls: Answers and chat by API.