Searching and extracting relevant passages and summaries

🔍 mSearch finds documents with similar meaning 🔍

Search requests

Relevant endpoints:

The two endpoints listed towards the end - search and answer - allow querying multiple collections at once. When using search across multiple collections, the embedding method used by those collections should be the same, to ensure compatible relevancy scores across collections.

A simple search request

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

{
  "query": "T-Shirts with animals on them"
}

A search request to return the full content of the 5 most relevant documents

Returning full content of documents is the default, as well as highlight on. Additionally, request the "sections" format instead of flat:

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

{
  "query": "T-Shirts with animals on them",
  "max_results": 5,
  "include_content": ["full"],
  "result_format": "sections",
  "highlight": true,
}

A search request to return just document summaries that fit into a token limit

Instead of full document content, clients can retrieve just document excerpts that together fit into a token limit. Replacing summaries by summary would format summaries as a single string in the response.

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

{
  "query": "Co je to DPH",
  "include_content": ["summaries"],
  "summary_config": {
    "max_tokens": 3000
  }
}

A search request to return full documents with highlight as well as summaries

Several types of content can be returned at once:

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

{
  "query": "Co je to DPH",
  "include_content": ["full", summaries"],
  "result_format": "sections",
  "summary_config": {
    "max_tokens": 3000
  }
}

Returning full document content

The query and search endpoints of msearch aim to retrieve the documents most relevant to a user query. This works at the level of documents as they were ingested. The include_content parameter controls whether to return the full documents, or just document summaries, a single summary, or their combination. Other commonly used parameters include:

There are several types of information about the retrieved documents that mSearch can return.

To include passages in the response, set the highlight parameter to true. It is recommended to use result_format set to sections when working with passages, as the section indexes and content character offsets point to document sections, and cannot be interpreted with the flat format.

Document formats

Full documents can be output in 2 formats:

Sample response showing "full" documents along with "passages" due to "highlight" enabled

{
  "search_id": "90ffb176-434d-4635-96ac-4c55817c3a2f"
  "documents": [
    {
      "document_id": "ZODPH155",
      "score": 0.5110244154930115,
      "source": "sem",
      "passages": [
        {
          "text": "odnést.\n(3) Prodávající je povinen na vyžádání zahraniční fyzické osoby vystavit doklad... ",
          "offsets": [
            866,
            1306
          ],
          "section_index": 2,
          "score": 0.47954487800598145
        },
        ...
      ],
      "sections": [
        {
          "type": "Id",
          "content": "ZODPH155"
        },
        {
          "type": "Paragraf",
          "content": "§ 84 DZ"
        },
        {
          "type": "Text",
          "content": "Vracení daně fyzickým osobám...
        },
        ...
      ]
    }
  ]
}

Returning only the relevant parts (summaries) of top documents

In addition or as an alternative to returning whole documents and their relevant passages, mSearch can return other types of content relevant to user query:

Sample response showing document summaries that fit in 3000 tokens

{
  "search_id": "90ffb176-434d-4635-96ac-4c55817c3a2f",
  "summaries": [
    {
      "document_id": "ZODPH148",
      "content": "§80 DZ\nVracení daně osobám požívajícím výsad a imunit\n(1) Pro účely tohoto zákona ..."
    },
    ...
  ],
  "metadata": {
    "tokens": {
      "prompt_tokens": 2438
    },
    "original_documents_count": 5,
    "summary_documents_count": 5,
    "summary_method": "first_relevant_3_then_relevant_21 distance=1",
    "message": "C. Represented 5 documents with total 12367 tokens by the first 2 docs abbreviated, 
                and the rest abbreviated even more to total 2438 tokens which is less than max 3000 configured"
  }
}

API reference