Answer questions and retrieve documents the answer was based upon

🔍 mSearch finds documents with similar meaning 🔍

Question answering

Use the answer endpoint: - POST /msearch/collections/answer

Get answer using collection's settings

POST https://api.msearch.themama.ai/msearch/collections/{collection_id}/search
Authorization: CENSORED
Content-Type: application/json

{
  "collections": ["{collection_id}"],
  "query": "Co je to DPH",
  "include_content": []
}

Get answer using dynamically provided LLM model and max_tokens limit

The answer endpoint can search more than one collection. When searching across multiple collections, those collections should use the same embedding method to ensure compatible relevancy scores across collections.

POST https://api.msearch.themama.ai/msearch/answer
Authorization: CENSORED
Content-Type: application/json

{
  "collections": ["{collection_id}"],
  "query": "Co je to DPH",
  "answer_config": {
    "service": "llm-service",
    "model": "model_deployment"
  },
  "summary_config": {
    "max_tokens": 6000
  },
  "include_content": []
}

An answer response

This includes the answer as follows:

{
  "answer": "DPH (daň z přidané hodnoty) je daň, která se vrací osobám požívajícím výsad a imunit podle smluv, které jsou součástí českého právního řádu. Těmito osobami mohou být diplomatické mise, konzulární úřady, zvláštní mise, mezinárodní organizace, jejich členové a rodinní příslušníci, pokud splňují určité podmínky. Nárok na vrácení daně se uplatňuje podáním daňového přiznání nebo žádosti o vrácení daně. Daň se vrací za zboží a služby, které tyto osoby použijí výlučně pro svou úřední nebo vlastní potřebu. Maximální výše vrácené daně a další podmínky se liší podle typu osoby a konkrétních okolností.",
  "answer_id": "bce214ac-c1f7-4de0-8b8f-934bf94b304e",
  "search_id": "2046a439-8396-4430-a0dc-523ef3491ba7",
  "metadata": {
    "tokens": {
      "prompt_tokens": 4498,
      "completion_tokens": 194,
      "total_tokens": 4692
    },
    "original_documents_count": 5,
    "summary_documents_count": 5,
    "summary_method": "first_full_then_relevant_3210 distance=0",
    "message": "B. Represented 5 documents with total 12367 tokens by the full text of the first 1 docs, and abbreviated the rest to total 5941 tokens which is less than max 6000 configured"
  }
}

The answer_id and search_id can be used for tracking the search and answer events. The metadata part includes: - tokens: usage as reported by the LLM used - original_documents_count: the number of documents that were retrieved, usually equal to max_results - summary_documents_count: the number of summarized documents that were passed to the LLM to generate the answer - summary_method and message: explanation of how documents were summarized to fit into the max_tokens limit

Including documents summaries used to generate the answer

One can optionally request the summaries of documents that took part in the answer generation to be included in the answer response, as well as the full documents retrieved, as described in the Search topic:

POST https://api.msearch.themama.ai/msearch/answer
Authorization: CENSORED
Content-Type: application/json

{
  "collections": ["{collection_id}"],
  "query": "Co je to DPH",
  "include_content": ["full", "summaries", "summary"]
}

Sample answer response including full documents as well as summaries in two forms

{
  "answer": "DPH (daň z přidané hodnoty) je daň, která se vrací osobám požívajícím výsad a imunit podle smluv, které jsou součástí českého právního řádu. Těmito osobami mohou být diplomatické mise, konzulární úřady, zvláštní mise, mezinárodní organizace, jejich členové a rodinní příslušníci, pokud splňují určité podmínky. Nárok na vrácení daně se uplatňuje podáním daňového přiznání nebo žádosti o vrácení daně. Daň se vrací za zboží a služby, které tyto osoby použijí výlučně pro svou úřední nebo vlastní potřebu. Maximální výše vrácené daně a další podmínky se liší podle typu osoby a konkrétních okolností.",
  "answer_id": "bce214ac-c1f7-4de0-8b8f-934bf94b304e",
  "search_id": "2046a439-8396-4430-a0dc-523ef3491ba7",
  "metadata": {
    "tokens": {
      "prompt_tokens": 4498,
      "completion_tokens": 194,
      "total_tokens": 4692
    },
    "original_documents_count": 5,
    "summary_documents_count": 5,
    "summary_method": "first_full_then_relevant_3210 distance=0",
    "message": "B. Represented 5 documents with total 12367 tokens by the full text of the first 1 docs, and abbreviated the rest to total 5941 tokens which is less than max 6000 configured"
  }
  "documents": [
    {
      "document_id": "ZODPH148",
      "score": 0.5110244154930115,
      "source": "sem",
      "passages": [ ... ]
    },
    ...
  ],
  "summaries": [
    {
      "document_id": "ZODPH148",
      "content": "Vracení daně osobám..."
    },
    ...
  ],
  "summary": "Vracení daně osobám ..."
}

API reference