Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 ChunkUpdateError(Exception):
  18. def __init__(self, code=None, message=None, details=None):
  19. self.code = code
  20. self.message = message
  21. self.details = details
  22. super().__init__(message)
  23. class Chunk(Base):
  24. def __init__(self, rag, res_dict):
  25. self.id = ""
  26. self.content = ""
  27. self.important_keywords = []
  28. self.questions = []
  29. self.create_time = ""
  30. self.create_timestamp = 0.0
  31. self.dataset_id = None
  32. self.document_name = ""
  33. self.document_id = ""
  34. self.available = True
  35. # Additional fields for retrieval results
  36. self.similarity = 0.0
  37. self.vector_similarity = 0.0
  38. self.term_similarity = 0.0
  39. self.positions = []
  40. self.doc_type = ""
  41. for k in list(res_dict.keys()):
  42. if k not in self.__dict__:
  43. res_dict.pop(k)
  44. super().__init__(rag, res_dict)
  45. def update(self, update_message: dict):
  46. res = self.put(f"/datasets/{self.dataset_id}/documents/{self.document_id}/chunks/{self.id}", update_message)
  47. res = res.json()
  48. if res.get("code") != 0:
  49. raise ChunkUpdateError(
  50. code=res.get("code"),
  51. message=res.get("message"),
  52. details=res.get("details")
  53. )