You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

chunk.py 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 .base import Base
  17. class Chunk(Base):
  18. def __init__(self, rag, res_dict):
  19. self.id = ""
  20. self.content = ""
  21. self.important_keywords = []
  22. self.questions = []
  23. self.create_time = ""
  24. self.create_timestamp = 0.0
  25. self.dataset_id = None
  26. self.document_name = ""
  27. self.document_id = ""
  28. self.available = True
  29. for k in list(res_dict.keys()):
  30. if k not in self.__dict__:
  31. res_dict.pop(k)
  32. super().__init__(rag, res_dict)
  33. def update(self, update_message: dict):
  34. res = self.put(f"/datasets/{self.dataset_id}/documents/{self.document_id}/chunks/{self.id}", update_message)
  35. res = res.json()
  36. if res.get("code") != 0:
  37. raise Exception(res["message"])