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 Update By Id

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

Overview

Concrete tool for updating knowledge base configuration including chunking method provided by RAGFlow CommonService.

Description

KnowledgebaseService.update_by_id is inherited from CommonService and performs a generic record update by primary key. When updating the chunking method, the parser_id field is set to one of the supported parser types. The method automatically sets update_time and update_date timestamps.

Usage

Call this to change the parser type (chunking method) of a knowledge base. The REST endpoint at POST /v1/kb/update validates ownership and name uniqueness before delegating.

Code Reference

Source Location

  • Repository: ragflow
  • File: api/db/services/common_service.py
  • Lines: L229-240

Signature

class CommonService:
    @classmethod
    @retry_db_operation
    def update_by_id(cls, pid, data):
        """Update a single record by ID.

        Args:
            pid: str - Record primary key (knowledge base ID).
            data: dict - Fields to update. For chunking: {"parser_id": "paper"}.

        Returns:
            int - Number of rows updated (1 on success).
        """
        data["update_time"] = current_timestamp()
        data["update_date"] = datetime_format(datetime.now())
        num = cls.model.update(data).where(cls.model.id == pid).execute()
        return num

Import

from api.db.services.knowledgebase_service import KnowledgebaseService
# KnowledgebaseService inherits update_by_id from CommonService

I/O Contract

Inputs

Name Type Required Description
pid str Yes Knowledge base ID
data dict Yes Fields to update (e.g., parser_id, name, description)

Outputs

Name Type Description
num int Number of rows updated (1 on success, 0 if not found)

Usage Examples

from api.db.services.knowledgebase_service import KnowledgebaseService

# Change chunking method to academic paper parser
KnowledgebaseService.update_by_id(
    "kb-uuid-123",
    {"parser_id": "paper"}
)

# Available parser_id values:
# "naive", "paper", "book", "laws", "presentation", "table",
# "qa", "picture", "one", "audio", "email", "tag", "resume", "knowledge_graph"

Related Pages

Implements Principle

Page Connections

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