Laws.Africa Developer Guide
  • Laws.Africa Developer Guide
  • Get Started
    • Introduction
    • Quick start
    • Works and expressions
    • Webhooks
    • Changelog
  • Tutorial
    • About the tutorial
    • Module 1: Build a legislation reader
      • Introductory concepts
      • Create a basic Django app
      • Create database models
      • Fetching the data
      • Work listing page
      • Expression detail page
      • Styling with Law Widgets
      • Adding interactivity
      • Staying up to date
    • Module 2: Enrichments and interactivity
      • Basic enrichments
      • Advanced enrichments
      • Advanced interactivity
    • Module 3: Text extraction for search and analysis
      • Why extracting text is important
      • Basics of text extraction
      • Advanced text extraction
      • Extracting text for analysis and machine learning
  • Content API Reference
    • About the Content API
    • Authentication
    • Pagination
    • Places
    • All work expressions
    • Single work expression
      • Commencements
      • Embedded images
      • Publication document
      • Table of Contents
      • Timeline
    • Taxonomy topics
    • Enrichment datasets
  • AI API Reference
    • About the AI API
    • Authentication
    • Knowledge Bases
  • How-to Guides
    • How to use the Table of Contents API
    • How to download images
Powered by GitBook
On this page
  1. AI API Reference

Knowledge Bases

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

PreviousAuthenticationNextHow to use the Table of Contents API

Last updated 1 month ago

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 . 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 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

Get details of a single knowledge base

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.

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:

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. 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
  }
}

Details of the legislative work, including information.

information for the portion of that work.

Details of the legislative work, including information.

FRBR URI
Table of Contents
FRBR URI
Laws.Africa Content API
Works and Expressions

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"
    }
  ]
}

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"
}
  • What are Knowledge Bases?
  • Legislation Knowledge Bases
  • Judgments Knowledge Bases
  • List available Knowledge Bases
  • GETExplore legal data Knowledge Bases for use with Generative AI (PREVIEW).
  • Get details of a single knowledge base
  • GETExplore legal data Knowledge Bases for use with Generative AI (PREVIEW).
  • Query a Knowledge Base
  • POSTQuery the knowledge base for matching items.
  • Legislation results
  • Judgment results

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
    }
  ]
}