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:Infiniflow Ragflow KnowledgebaseService Create With Name

From Leeroopedia
Knowledge Sources
Domains RAG, Knowledge_Management
Last Updated 2026-02-12 06:00 GMT

Overview

Concrete tool for creating knowledge base records provided by the RAGFlow KnowledgebaseService.

Description

The KnowledgebaseService.create_with_name class method encapsulates the full creation logic for a knowledge base (dataset). It validates the name, deduplicates within the tenant scope, verifies tenant existence, builds the payload with defaults, and persists via peewee ORM. This method is the canonical entry point used by both the REST API endpoint (POST /v1/kb/create) and internal callers.

Usage

Import and call this method when programmatically creating a new knowledge base. The REST endpoint at api/apps/kb_app.py delegates to this method after authentication.

Code Reference

Source Location

  • Repository: ragflow
  • File: api/db/services/knowledgebase_service.py
  • Lines: L376-423

Signature

class KnowledgebaseService(CommonService):
    model = Knowledgebase

    @classmethod
    @DB.connection_context()
    def create_with_name(
        cls,
        *,
        name: str,
        tenant_id: str,
        parser_id: str | None = None,
        **kwargs
    ) -> tuple[bool, dict | str]:
        """Create a dataset (knowledgebase) by name with kb_app defaults.

        Args:
            name: Dataset name (required, validated for length and emptiness).
            tenant_id: Owner tenant ID.
            parser_id: Parser type (defaults to "naive"). Options: "naive", "paper",
                       "book", "laws", "presentation", "table", "qa", "picture",
                       "one", "audio", "email", "tag".
            **kwargs: Optional fields - description, language, permission, avatar,
                      parser_config.

        Returns:
            (ok: bool, model_or_msg): On success (True, Knowledgebase instance);
                                       on failure (False, error_message).
        """

Import

from api.db.services.knowledgebase_service import KnowledgebaseService

I/O Contract

Inputs

Name Type Required Description
name str Yes Dataset name (max bytes: DATASET_NAME_LIMIT)
tenant_id str Yes Owner tenant UUID
parser_id str or None No Parser type (default: "naive")
description str No Human-readable description
language str No Document language hint
permission str No Access permission level
avatar str No Avatar image path
parser_config dict No Parser-specific configuration

Outputs

Name Type Description
ok bool True on success, False on validation failure
result Knowledgebase or str Knowledgebase model instance on success, error message on failure

Usage Examples

Create a Basic Knowledge Base

from api.db.services.knowledgebase_service import KnowledgebaseService

# Create with defaults (naive parser)
ok, result = KnowledgebaseService.create_with_name(
    name="Technical Documentation",
    tenant_id="user-uuid-123"
)

if ok:
    kb = result
    print(f"Created KB: {kb.id}")
else:
    print(f"Error: {result}")

Create with Specific Parser

ok, result = KnowledgebaseService.create_with_name(
    name="Legal Contracts",
    tenant_id="user-uuid-123",
    parser_id="laws",
    description="Collection of legal documents",
    language="English"
)

Related Pages

Implements Principle

Page Connections

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