Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Langgenius Dify FetchDatasets

From Leeroopedia
Revision as of 11:27, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Langgenius_Dify_FetchDatasets.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources Domains Last Updated
Dify LLM_Applications, Frontend, API 2026-02-12 00:00 GMT

Overview

Description

fetchDatasets is the frontend service function for retrieving a paginated list of knowledge bases (datasets) available in the current workspace. It constructs a query string from the provided parameters using the qs library and sends a GET request to the specified URL endpoint. The function supports pagination, keyword search, and tag-based filtering.

This function is the entry point for the knowledge base selection workflow: when a developer configures an application to use RAG, they first browse available datasets using fetchDatasets, then inspect individual datasets via fetchDatasetDetail.

The companion function fetchDatasetDetail (lines 61-63) retrieves the full metadata for a single dataset, including its name, description, indexing technique, embedding model, document count, and retrieval configuration. It sends a GET request to /datasets/{datasetId} and returns a DataSet object.

Usage

Call fetchDatasets to populate the dataset selection UI in the application configuration panel. Use the pagination parameters to implement infinite scroll or page-based navigation. Combine with fetchDatasetDetail to show detailed information when a user selects a specific dataset for connection.

Code Reference

Source Location

web/service/datasets.ts, lines 79-82

Signature

export const fetchDatasets = (
  { url, params }: FetchDatasetsParams
): Promise<DataSetListResponse> => {
  const urlParams = qs.stringify(params, { indices: false })
  return get<DataSetListResponse>(`${url}?${urlParams}`)
}

Related: fetchDatasetDetail (lines 61-63):

export const fetchDatasetDetail = (datasetId: string): Promise<DataSet> => {
  return get<DataSet>(`/datasets/${datasetId}`)
}

Import

import { fetchDatasets, fetchDatasetDetail } from '@/service/datasets'

I/O Contract

Inputs (fetchDatasets)

Parameter Type Required Description
url string Yes The API endpoint URL for listing datasets (e.g., '/datasets').
params.page number Yes The page number for pagination (1-based).
params.limit number Yes The number of results per page.
params.tag_ids string[] No Tag IDs to filter datasets by associated tags.
params.keyword string No Search keyword to filter datasets by name or description.

The FetchDatasetsParams type is defined as:

export type FetchDatasetsParams = {
  url: string
  params: {
    page: number
    limit: number
    tag_ids?: string[]
    keyword?: string
  }
}

Inputs (fetchDatasetDetail)

Parameter Type Required Description
datasetId string Yes The unique identifier of the dataset to retrieve.

Outputs (fetchDatasets)

Field Type Description
data DataSet[] Array of dataset objects, each containing id, name, description, permission, indexing_technique, embedding_model, embedding_model_provider, and other metadata.
has_more boolean Whether additional pages of results exist beyond the current page.
limit number The page size used for this response.
page number The current page number.
total number The total number of datasets matching the query.

Outputs (fetchDatasetDetail)

Field Type Description
(return) Promise<DataSet> Resolves to the full dataset entity with all metadata fields including id, name, description, permission, indexing_technique, retrieval_model, embedding_model, embedding_model_provider, doc_form, and icon_info.

Usage Examples

Fetching the first page of datasets with a keyword filter

import { fetchDatasets } from '@/service/datasets'

const response = await fetchDatasets({
  url: '/datasets',
  params: {
    page: 1,
    limit: 20,
    keyword: 'product documentation',
  },
})

console.log(response.data)     // DataSet[]
console.log(response.has_more) // true if more pages exist
console.log(response.total)    // total matching datasets

Fetching dataset detail for connection to an app

import { fetchDatasetDetail } from '@/service/datasets'

const dataset = await fetchDatasetDetail('dataset-id-abc123')

console.log(dataset.name)              // 'Product Documentation'
console.log(dataset.indexing_technique) // 'high_quality' or 'economy'
console.log(dataset.embedding_model)   // 'text-embedding-ada-002'

Filtering datasets by tags

import { fetchDatasets } from '@/service/datasets'

const response = await fetchDatasets({
  url: '/datasets',
  params: {
    page: 1,
    limit: 10,
    tag_ids: ['tag-engineering', 'tag-support'],
  },
})

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment