mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-08-14 06:05:59 +08:00
Fix raptor issue (#3737)
### What problem does this PR solve? #3732 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
parent
a0c0a957b4
commit
27cd765d6f
@ -44,7 +44,7 @@ class RecursiveAbstractiveProcessing4TreeOrganizedRetrieval:
|
||||
optimal_clusters = n_clusters[np.argmin(bics)]
|
||||
return optimal_clusters
|
||||
|
||||
def __call__(self, chunks: tuple[str, np.ndarray], random_state, callback=None):
|
||||
def __call__(self, chunks, random_state, callback=None):
|
||||
layers = [(0, len(chunks))]
|
||||
start, end = 0, len(chunks)
|
||||
if len(chunks) <= 1: return
|
||||
@ -57,10 +57,12 @@ class RecursiveAbstractiveProcessing4TreeOrganizedRetrieval:
|
||||
len_per_chunk = int((self._llm_model.max_length - self._max_token) / len(texts))
|
||||
cluster_content = "\n".join([truncate(t, max(1, len_per_chunk)) for t in texts])
|
||||
cnt = self._llm_model.chat("You're a helpful assistant.",
|
||||
[{"role": "user", "content": self._prompt.format(cluster_content=cluster_content)}],
|
||||
[{"role": "user",
|
||||
"content": self._prompt.format(cluster_content=cluster_content)}],
|
||||
{"temperature": 0.3, "max_tokens": self._max_token}
|
||||
)
|
||||
cnt = re.sub("(······\n由于长度的原因,回答被截断了,要继续吗?|For the content length reason, it stopped, continue?)", "", cnt)
|
||||
cnt = re.sub("(······\n由于长度的原因,回答被截断了,要继续吗?|For the content length reason, it stopped, continue?)", "",
|
||||
cnt)
|
||||
logging.debug(f"SUM: {cnt}")
|
||||
embds, _ = self._embd_model.encode([cnt])
|
||||
with lock:
|
||||
@ -113,3 +115,5 @@ class RecursiveAbstractiveProcessing4TreeOrganizedRetrieval:
|
||||
start = end
|
||||
end = len(chunks)
|
||||
|
||||
return chunks
|
||||
|
||||
|
@ -344,7 +344,7 @@ def run_raptor(row, chat_mdl, embd_mdl, callback=None):
|
||||
row["parser_config"]["raptor"]["threshold"]
|
||||
)
|
||||
original_length = len(chunks)
|
||||
raptor(chunks, row["parser_config"]["raptor"]["random_seed"], callback)
|
||||
chunks = raptor(chunks, row["parser_config"]["raptor"]["random_seed"], callback)
|
||||
doc = {
|
||||
"doc_id": row["doc_id"],
|
||||
"kb_id": [str(row["kb_id"])],
|
||||
|
Loading…
x
Reference in New Issue
Block a user