-
Notifications
You must be signed in to change notification settings - Fork 376
refactor(rag): introduce doc_service and migrate Document off legacy doc managers #1069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ChenJiahaoST
wants to merge
56
commits into
LazyAGI:main
Choose a base branch
from
ChenJiahaoST:cjh/refact-doc-manager
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
0977e0f
feature update from custom version of doc processor
3500040
enhance worker for parsing service
8c76b15
add doc and modify bt review
7910ff8
Merge remote-tracking branch 'origin/main' into cjh/update-from-custo…
f82f0dd
modify code
e772a42
fix schema_extractor bug
wzh1994 d5ec170
Merge remote-tracking branch 'origin/main' into cjh/update-from-custo…
9c714de
temp
wzh1994 d40ad66
modify
3c417a3
Merge remote-tracking branch 'origin/main' into wzh/doc_process
wzh1994 2e64bda
temp code for mock api
e3e18a6
Merge from origin/main
809821f
fix dbname init
ChenJiahaoST 61c5bec
fix tidb primary kay type
ChenJiahaoST cea23e3
temp
56cbcf4
fix api error
e387b3c
Merge remote-tracking branch 'origin/main' into cjh/update-from-custo…
e4e1e4d
fix node transform fallback
03a97e4
update kb api
aaa3f49
fix error
ee4ba13
fix delete params
3c02f74
modify api
83609a6
Merge remote-tracking branch origin/main into cjh/refact-doc-manager
c81dafd
temp doc server example
fd01c8e
Merge remote-tracking branch 'origin/main' into cjh/update-from-custo…
9ca28cb
lint
5bb2625
tmp code
fa3ab7b
tmp example
24b9ffa
fix docnode copy
3c7f948
fix sqlmanager pg adaption
914dd89
Merge remote-tracking branch origin/main into cjh/refact-doc-manager
ca6e49c
Merge remote-tracking branch origin/main into cjh/refact-doc-manager
77cc90d
fix reparse whole file
c73faba
add chunk list api
318e966
fix opensearch query
20e9373
support real offset for segment store
dce9402
Merge remote-tracking branch origin/main into cjh/update-from-custom-…
72f7406
Merge branch cjh/update-from-custom-processor into cjh/refact-doc-man…
786ecbe
refactor: expose public doc and processor APIs
3fb0f51
fix file transfer
230fdd0
fix
2ac3cf9
fix: honor excluded metadata in text splitter
6cc9176
fix: guard doc path conflicts in doc manager
7541505
fix: make mineru pipeline backend more robust
084060b
fix: reset doc impl monitor lock on pickle
251259d
fix opensearch segment deserialization
b9c835d
fix doc service mock test lint
5681411
Merge remote-tracking branch 'origin/main' into cjh/refact-doc-manager
05346f0
Merge branch 'LazyAGI:main' into cjh/refact-doc-manager
ChenJiahaoST 5f7c27f
Converge document manager parameters
9fe7e1a
Export DocServer and trim docservice docs
49535df
Unify DocServer doc registration
473f5e2
Address doc_service review feedback
baefa88
Tighten doc manager formatting
50dad37
Finish remaining doc_service review follow-ups
4c5ff62
Fix doc UI and cancel status regressions
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ __pycache__ | |
| test/ | ||
| dist/ | ||
| tmp/ | ||
| tmp*/ | ||
| build | ||
| *.lock | ||
| *.db | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| '''Connect a Document to a deployed DocServer. | ||
|
|
||
| Start DocServer first: | ||
| python examples/rag/doc_service_standalone.py --wait | ||
|
|
||
| Run this example: | ||
| python examples/rag/doc_service_mock_example.py --doc-server-url http://127.0.0.1:8848 | ||
| ''' | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import os | ||
| import tempfile | ||
| import time | ||
|
|
||
| from lazyllm import Document | ||
| from lazyllm.tools.rag.doc_service import DocServer | ||
| from lazyllm.tools.rag.doc_service.base import AddFileItem, AddRequest | ||
|
|
||
|
|
||
| def _normalize_base_url(url: str) -> str: | ||
| url = url.rstrip('/') | ||
| if url.endswith('/_call') or url.endswith('/generate'): | ||
| return url.rsplit('/', 1)[0] | ||
| return url | ||
|
|
||
|
|
||
| def _wait_task(server: DocServer, task_id: str, timeout: float = 30.0): | ||
| deadline = time.time() + timeout | ||
| while time.time() < deadline: | ||
| task = server.get_task(task_id)['data'] | ||
| if task['status'] in {'SUCCESS', 'FAILED', 'CANCELED', 'DELETED'}: | ||
| return task | ||
| time.sleep(0.5) | ||
| raise TimeoutError(f'task {task_id} did not finish in time') | ||
|
|
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser(description='Connect a Document to an existing DocServer.') | ||
| parser.add_argument('--doc-server-url', type=str, required=True, help='Existing DocServer base URL.') | ||
| parser.add_argument('--algo-id', type=str, default='doc_service_demo_algo', help='Document algorithm ID.') | ||
| parser.add_argument('--kb-id', type=str, default='__default__', help='Knowledge base ID.') | ||
| args = parser.parse_args() | ||
|
|
||
| doc_server = DocServer(url=_normalize_base_url(args.doc_server_url)) | ||
| with tempfile.TemporaryDirectory(prefix='lazyllm_doc_service_example_') as dataset_dir: | ||
| file_path = os.path.join(dataset_dir, 'demo.txt') | ||
| with open(file_path, 'w', encoding='utf-8') as file: | ||
| file.write('hello from a real doc_service example\n') | ||
|
|
||
| # Step 1: create a Document and bind it to the deployed DocServer. | ||
| document = Document(dataset_path=dataset_dir, manager=doc_server, name=args.algo_id) | ||
| document.start() | ||
|
|
||
| try: | ||
| base_url = _normalize_base_url(args.doc_server_url) | ||
| print(f'DocServer URL: {base_url}') | ||
| print(f'DocServer Docs: {base_url}/docs') | ||
|
|
||
| # Step 2: add a local file through the DocServer client. | ||
| response = doc_server.add(AddRequest( | ||
| kb_id=args.kb_id, | ||
| algo_id=args.algo_id, | ||
| items=[AddFileItem(file_path=file_path)], | ||
| )) | ||
| item = response['data']['items'][0] | ||
| print(f'Doc ID: {item["doc_id"]}') | ||
| print(f'Task ID: {item["task_id"]}') | ||
|
|
||
| # Step 3: wait for the asynchronous parse task to finish. | ||
| task = _wait_task(doc_server, item['task_id']) | ||
| print(f'Task Status: {task["status"]}') | ||
|
|
||
| # Step 4: list documents from the target knowledge base. | ||
| docs = doc_server.list_docs( | ||
| kb_id=args.kb_id, algo_id=args.algo_id, include_deleted_or_canceled=False | ||
| )['data']['items'] | ||
| print(f'Doc Count In {args.kb_id}: {len(docs)}') | ||
| finally: | ||
| document.stop() | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.