All Products
Search
Document Center

Data Management:RetrieveKnowledgeBase

Last Updated:Jun 09, 2026

Query a knowledge base

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

No authorization for this operation. If you encounter issues with this operation, contact technical support.

Request parameters

Parameter

Type

Required

Description

Example

KbUuid

string

Yes

The ID of the knowledge base.

kb-***

Query

string

Yes

The query text.

What is GraphRAG?

TopK

integer

No

The number of top-ranked results to return.

10

Filter

string

No

A filter for the data, specified as a SQL WHERE clause.

title = 'test' AND name like 'test%'

Metrics

string

No

The distance metric for retrieval. If unspecified, this defaults to the metric configured for the knowledge base. Only set this parameter if you have specific requirements.

Valid values:

  • l2: Euclidean distance.

  • ip: Inner product.

  • cosine: Cosine similarity.

cosine

HybridSearch

string

No

The hybrid search algorithm. If this parameter is not set, the system directly compares and ranks the scores from the dense vector and full-text searches.

Valid values:

  • RRF: Reciprocal Rank Fusion. This method uses a parameter k to control the fusion effect. For more information, see the HybridSearchArgs configuration.

  • Weight: Weighted ranking. This method applies weights to the vector and full-text search scores before ranking. For more information, see the HybridSearchArgs configuration.

  • Cascaded: Performs a full-text search first, followed by a vector search on the results of the full-text search.

RRF

HybridSearchArgs

string

No

Parameters for the specified HybridSearch algorithm. Both RRF and Weight are supported. You can use the HybridPathsSetting object to specify the retrieval paths: dense vector (dense), sparse vector (sparse), and full-text search (fulltext). If this object is not provided, the default retrieval paths are dense and fulltext.

  • RRF: Specifies the constant k in the scoring formula 1/(k+rank_i). The value of k must be an integer greater than 1. The format is as follows:

{
  "HybridPathsSetting": {
    "paths": "dense,fulltext"
  },
  "RRF": {
    "k": 60
  }
}
  • Weight:
    • Two-path recall (do not specify HybridPathsSetting; specify only alpha):
      • The score is calculated using the formula: alpha * dense_score + (1-alpha) * fulltext_score. The alpha parameter balances the scores from the dense vector and full-text searches. Its value must be in the range [0, 1], where 0 relies solely on full-text search, and 1 relies solely on dense vector search.

{ 
   "Weight": {
    "alpha": 0.5
   }
}
  • Three-path recall:
    • The score is calculated using the formula: normalized_dense * dense_score + normalized_sparse * sparse_score + normalized_fulltext * fulltext_score. The dense, sparse, and fulltext parameters are the weights for the dense vector, sparse vector, and full-text searches, respectively. Their values must be 0 or greater. The system automatically normalizes the weights to sum to 1 (for example, normalized_x = x / (dense + sparse + fulltext)).

{
  "HybridPathsSetting": {
     "paths": "dense,sparse,fulltext"
   },
  "Weight": {
    "dense": 0.5,
    "sparse": 0.3,
    "fulltext": 0.2
  }
}

{ \"Weight\": { \"alpha\": 0.5 } }

IncludeVector

boolean

No

Specifies whether to include the vector in the results. The default value is false.

Note
  • false: The vector is not returned.

  • true: The vector is returned.

false

IncludeMetadataFields

string

No

The metadata fields to return, separated by commas. By default, no metadata fields are returned.

title,page

RerankFactor

number

No

The factor used to rerank vector search results. The value must be in the range (1, 5].

Note
  • Reranking may be slow if document chunks are sparse.

  • The number of items to rerank, calculated as ceil(TopK * RerankFactor), should not exceed 50.

2

RecallWindow

string

No

The recall window. If specified, this parameter expands the context of the retrieved results. The format is a two-element array [A, B], where -10 <= A <= 0 and 0 <= B <= 10.

Note
  • Recommended when document chunks are highly fragmented, which might cause context loss during retrieval.

  • Reranking occurs before windowing is applied.

[-5,5]

OrderBy

string

No

The field to use for sorting the results. By default, this parameter is empty.

The field must be a metadata field or a default table field, such as id. Supported formats include:

You can specify a single field (for example, chunk_id), multiple comma-separated fields (for example, block_id, chunk_id), or fields with descending order (for example, block_id DESC, chunk_id DESC).

created_at

Offset

integer

No

The offset for pagination.

0

Response elements

Element

Type

Description

Example

object

The response object.

RequestId

string

The unique request ID. Use this ID to troubleshoot errors.

67E910F2-4B62-5B0C-ACA3-7547695C****

Data

object

The response payload.

Results

array<object>

The retrieved results.

array<object>

A single retrieval result.

Id

string

The unique ID of the vector.

3b35c95-57f3-442f-9220-xxxxx

Content

string

The content of the retrieved text chunk.

GraphRAG (Graph Retrieval-Augmented Generation) is an advanced AI framework that combines Knowledge Graphs with Large Language Models (LLMs) to improve the accuracy, context, and reasoning capabilities of information retrieval and generation.

FileName

string

The name of the source document.

1.txt

LoaderMetadata

string

The metadata generated by the document loader.

{"page_pos": 1}

Score

number

The similarity score of the result. This score depends on the distance metric (l2, ip, or cosine) specified when the index was created.

0.81

Vector

array

The vector data as an array of floating-point numbers.

number

A single floating-point value from the vector.

1.2123

Metadata

object

A key-value map of the metadata.

{"title":"test"}

RerankScore

number

The rerank score.

6.2345

RetrievalSource

integer

The method used for retrieval. Valid values: 1 (vector retrieval), 2 (full-text search), and 3 (hybrid search).

1

Matches

array<object>

Matched items from the windowing process.

array<object>

A matched data object.

Content

string

The text content.

GraphRAG (Graph Retrieval-Augmented Generation) is an advanced AI framework that combines Knowledge Graphs with Large Language Models (LLMs) to improve the accuracy, context, and reasoning capabilities of information retrieval and generation.

FileName

string

The name of the source document.

1.txt

Id

string

The unique ID of the vector.

3b35c95-57f3-442f-9220-xxxxx

LoaderMetadata

string

The metadata generated by the document loader.

{"page_pos": 1}

Metadata

object

A key-value map of the metadata.

{"title":"test"}

ErrorCode

string

The error code for a failed request.

KnowledgeBaseNotFound

Success

boolean

Indicates whether the request was successful. Valid values:

  • true: The request was successful.

  • false: The request failed.

true

ErrorMessage

string

The error message for a failed request.

Resource not found kb-***

Examples

Success response

JSON format

{
  "RequestId": "67E910F2-4B62-5B0C-ACA3-7547695C****",
  "Data": {
    "Results": [
      {
        "Id": "3b35c95-57f3-442f-9220-xxxxx",
        "Content": "GraphRAG (Graph Retrieval-Augmented Generation) is an advanced AI framework that combines Knowledge Graphs with Large Language Models (LLMs) to improve the accuracy, context, and reasoning capabilities of information retrieval and generation.",
        "FileName": "1.txt",
        "LoaderMetadata": "{\"page_pos\": 1}",
        "Score": 0.81,
        "Vector": [
          1.2123
        ],
        "Metadata": {
          "title": "test"
        },
        "RerankScore": 6.2345,
        "RetrievalSource": 1
      }
    ],
    "Matches": [
      {
        "Content": "GraphRAG (Graph Retrieval-Augmented Generation) is an advanced AI framework that combines Knowledge Graphs with Large Language Models (LLMs) to improve the accuracy, context, and reasoning capabilities of information retrieval and generation.",
        "FileName": "1.txt",
        "Id": "3b35c95-57f3-442f-9220-xxxxx",
        "LoaderMetadata": "{\"page_pos\": 1}",
        "Metadata": {
          "title": "test"
        }
      }
    ]
  },
  "ErrorCode": "KnowledgeBaseNotFound",
  "Success": true,
  "ErrorMessage": "Resource not found kb-***"
}

Error codes

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.