您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #
  2. # Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. from pathlib import Path
  17. from ragflow_sdk import DataSet, Document, RAGFlow
  18. from utils.file_utils import create_txt_file
  19. # DATASET MANAGEMENT
  20. def batch_create_datasets(client: RAGFlow, num: int) -> list[DataSet]:
  21. return [client.create_dataset(name=f"dataset_{i}") for i in range(num)]
  22. # FILE MANAGEMENT WITHIN DATASET
  23. def bulk_upload_documents(dataset: DataSet, num: int, tmp_path: Path) -> list[Document]:
  24. document_infos = []
  25. for i in range(num):
  26. fp = create_txt_file(tmp_path / f"ragflow_test_upload_{i}.txt")
  27. with fp.open("rb") as f:
  28. blob = f.read()
  29. document_infos.append({"display_name": fp.name, "blob": blob})
  30. return dataset.upload_documents(document_infos)
  31. # CHUNK MANAGEMENT WITHIN DATASET
  32. def batch_add_chunks(document: Document, num: int):
  33. return [document.add_chunk(content=f"chunk test {i}") for i in range(num)]