Knowledge Bases

Use knowledge bases to find legal information related to a query.

What are Knowledge Bases?

A Knowledge Base (KB) is a database of legal information stored using an embedding database. You can use the retrieve API to query the Knowledge Base for items of legal data that match a query.

Legislation Knowledge Bases

Our legislation Knowledge Bases contain the full text of all the digitised legislation that is available through the Laws.Africa Content API. The legislation is split into portions (chapters, sections, paragraphs, etc.) and embeddings are calculated for each portion. These embeddings make it possible to perform semantic queries against the data to find portions relevant to a keyword, phrase or question.

Knowledge Bases include only the most recent version of legislation. See Works and Expressions for more details on how legislation changes over time.

Judgments Knowledge Bases

Our judgments Knowledge Bases contain the full text of all the court judgments (case law) that is available from our various Legal Information Institute (LII) partner websites. The judgments are split into chunks of text (along page boundaries, if pages are available) and embeddings are calculated for each chunk. These embeddings make it possible to perform semantic queries against the judgment dataset.

List available Knowledge Bases

Explore legal data Knowledge Bases for use with Generative AI (PREVIEW).

get

Get details of Laws.Africa's Knowledge Bases.

Note: this API is a preview and may change in future.

Authorizations
Query parameters
pageintegerOptional

A page number within the paginated result set.

page_sizeintegerOptional

Number of results to return per page.

Responses
200Success
application/json
get
GET /ai/v1/knowledge-bases HTTP/1.1
Host: 
Accept: */*
200Success
{
  "count": 123,
  "next": "text",
  "previous": "text",
  "results": [
    {
      "code": "text",
      "name": "text",
      "description": "text",
      "url": "https://example.com"
    }
  ]
}

Get details of a single knowledge base

Explore legal data Knowledge Bases for use with Generative AI (PREVIEW).

get

Get details of Laws.Africa's Knowledge Bases.

Note: this API is a preview and may change in future.

Authorizations
Path parameters
codestringRequired

Unique code identifying this knowledge base

Responses
200Success
application/json
get
GET /ai/v1/knowledge-bases/{code} HTTP/1.1
Host: 
Accept: */*
200Success
{
  "code": "text",
  "name": "text",
  "description": "text",
  "url": "https://example.com"
}

Query a Knowledge Base

Use the retrieve API to query a Knowledge Base for information matching keywords or phrases.

When you query a knowledge base, you must submit a POST request:

  1. Identify the Knowledge Base to query using its code in the URL of the request.

  2. Specify the text to search the Knowledge Base for using the text parameter.

The API will return matching items (portions of legislation) that match your query, including a score, the text of the portion, and metadata.

Query the knowledge base for matching items.

post

Retrieve items from the knowledge base that match your query.

Authorizations
Path parameters
codestringRequired

Unique code identifying this knowledge base

Body

Details to retrieve items from a knowledge base.

textstringRequired

The text to find matching items for

top_kinteger · min: 1 · max: 100Optional

Number of results to return

Default: 10
Responses
200Success
application/json
post
POST /ai/v1/knowledge-bases/{code}/retrieve HTTP/1.1
Host: 
Content-Type: application/json
Accept: */*
Content-Length: 26

{
  "text": "text",
  "top_k": 10
}
200Success
{
  "results": [
    {
      "content": {
        "text": "text"
      },
      "metadata": {
        "ANY_ADDITIONAL_PROPERTY": "anything"
      },
      "score": 1
    }
  ]
}

Legislation results

The Retrieve API for legislation Knowledge Bases returns the text of the matched provision, the score of the match (a lower score is better), and metadata for the portion. This provides very precise details on the portion of legislation that matched the query, allowing you to provide concrete citation information to your user.

The metadata includes a combination of:

  1. Details of the legislative work, including FRBR URI information.

  2. Table of Contents information for the portion of that work.

For example:

{
  "metadata": {
    "portion_id": "chp_2__sec_2",
    "frbr_locality": "jhb",
    "portion_num": "2.",
    "portion_title": "2. Restriction on number of dogs",
    "frbr_place": "za-jhb",
    "title": "Dogs and Cats",
    "expression_date": "2019-09-04",
    "portion_frbr_uri": "/akn/za-jhb/act/by-law/2006/dogs-and-cats/eng/~chp_2__sec_2",
    "work_frbr_uri": "/akn/za-jhb/act/by-law/2006/dogs-and-cats",
    "portion_heading": "Restriction on number of dogs",
    "frbr_country": "za",
    "portion_type": "section"
  }
}

Judgment results

The Retrieve API for judgment Knowledge Bases returns the text of the matched chunk, the score of the match (a lower score is better), and metadata for the chunk.

Up to three chunks will be returned for the same judgment.

The metadata for each chunk includes a combination of:

  1. Details of the legislative work, including FRBR URI information.

  2. The 1-based page number, where available.

For example:

{
  "metadata": {
    "work_frbr_uri": "/akn/za/judgment/zalcjhb/2014/139",
    "frbr_place": "za",
    "frbr_country": "za",
    "title": "NEHAWU obo Manyana and Another v Masege N.O. and Others (JR 363/2012) [2014] ZALCJHB 139 (8 April 2014)",
    "expression_date": "2014-04-08",
    "expression_frbr_uri": "/akn/za/judgment/zalcjhb/2014/139/eng@2014-04-08",
    "portion_type": "page",
    "portion_id": 30
  }
}

Last updated