Skip to content

Commit 1429f29

Browse files
change chunk.status to chunk.available (infiniflow#2646)
### What problem does this PR solve? infiniflow#1102 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
1 parent 4f560a9 commit 1429f29

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

api/apps/sdk/doc.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,8 @@ def set(tenant_id):
609609
d["content_sm_ltks"] = rag_tokenizer.fine_grained_tokenize(d["content_ltks"])
610610
d["important_kwd"] = req["important_keywords"]
611611
d["important_tks"] = rag_tokenizer.tokenize(" ".join(req["important_keywords"]))
612-
if "available_int" in req:
613-
d["available_int"] = req["available_int"]
612+
if "available" in req:
613+
d["available_int"] = req["available"]
614614

615615
try:
616616
tenant_id = DocumentService.get_tenant_id(req["document_id"])

sdk/python/ragflow/modules/chunk.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __init__(self, rag, res_dict):
1111
self.knowledgebase_id = None
1212
self.document_name = ""
1313
self.document_id = ""
14-
self.status = "1"
14+
self.available = 1
1515
for k in list(res_dict.keys()):
1616
if k not in self.__dict__:
1717
res_dict.pop(k)
@@ -39,7 +39,7 @@ def save(self) -> bool:
3939
"content": self.content,
4040
"important_keywords": self.important_keywords,
4141
"document_id": self.document_id,
42-
"status": self.status,
42+
"available": self.available,
4343
})
4444
res = res.json()
4545
if res.get("retmsg") == "success":

sdk/python/test/t_document.py

+17-9
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,12 @@ def test_parse_and_cancel_document(self):
151151
name3 = 'westworld.pdf'
152152
path = 'test_data/westworld.pdf'
153153

154-
155154
# Create a document in the dataset using the file path
156155
rag.create_document(ds, name=name3, blob=open(path, "rb").read())
157156

158157
# Retrieve the document by name
159158
doc = rag.get_document(name="westworld.pdf")
160159

161-
162160
# Initiate asynchronous parsing
163161
doc.async_parse()
164162

@@ -231,7 +229,7 @@ def test_bulk_parse_and_cancel_documents(self):
231229
def test_parse_document_and_chunk_list(self):
232230
rag = RAGFlow(API_KEY, HOST_ADDRESS)
233231
ds = rag.create_dataset(name="God7")
234-
name='story.txt'
232+
name = 'story.txt'
235233
path = 'test_data/story.txt'
236234
# name = "Test Document rag.txt"
237235
# blob = " Sample document content for rag test66. rag wonderful apple os documents apps. Sample document content for rag test66. rag wonderful apple os documents apps.Sample document content for rag test66. rag wonderful apple os documents apps.Sample document content for rag test66. rag wonderful apple os documents apps. Sample document content for rag test66. rag wonderful apple os documents apps. Sample document content for rag test66. rag wonderful apple os documents apps. Sample document content for rag test66. rag wonderful apple os documents apps. Sample document content for rag test66. rag wonderful apple os documents apps. Sample document content for rag test66. rag wonderful apple os documents apps. Sample document content for rag test66. rag wonderful apple os documents apps. Sample document content for rag test66. rag wonderful apple os documents apps. Sample document content for rag test66. rag wonderful apple os documents apps."
@@ -266,21 +264,31 @@ def test_delete_chunk_of_chunk_list(self):
266264
assert chunk is not None, "Chunk is None"
267265
assert isinstance(chunk, Chunk), "Chunk was not added to chunk list"
268266
doc = rag.get_document(name='story.txt')
269-
chunk_count_before=doc.chunk_count
267+
chunk_count_before = doc.chunk_count
270268
chunk.delete()
271269
doc = rag.get_document(name='story.txt')
272-
assert doc.chunk_count == chunk_count_before-1, "Chunk was not deleted"
273-
270+
assert doc.chunk_count == chunk_count_before - 1, "Chunk was not deleted"
271+
274272
def test_update_chunk_content(self):
275273
rag = RAGFlow(API_KEY, HOST_ADDRESS)
276274
doc = rag.get_document(name='story.txt')
277275
chunk = doc.add_chunk(content="assssddd")
278276
assert chunk is not None, "Chunk is None"
279277
assert isinstance(chunk, Chunk), "Chunk was not added to chunk list"
280278
chunk.content = "ragflow123"
281-
res=chunk.save()
282-
assert res is True, f"Failed to update chunk, error: {res}"
283-
279+
res = chunk.save()
280+
assert res is True, f"Failed to update chunk content, error: {res}"
281+
282+
def test_update_chunk_available(self):
283+
rag = RAGFlow(API_KEY, HOST_ADDRESS)
284+
doc = rag.get_document(name='story.txt')
285+
chunk = doc.add_chunk(content="ragflow")
286+
assert chunk is not None, "Chunk is None"
287+
assert isinstance(chunk, Chunk), "Chunk was not added to chunk list"
288+
chunk.available = 0
289+
res = chunk.save()
290+
assert res is True, f"Failed to update chunk status, error: {res}"
291+
284292
def test_retrieval_chunks(self):
285293
rag = RAGFlow(API_KEY, HOST_ADDRESS)
286294
ds = rag.create_dataset(name="God8")

0 commit comments

Comments
 (0)