Skip to content
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

refactor: RAG Refactor #985

Merged
merged 58 commits into from
Jan 3, 2024
Merged

refactor: RAG Refactor #985

merged 58 commits into from
Jan 3, 2024

Conversation

Aries-ckt
Copy link
Collaborator

@Aries-ckt Aries-ckt commented Dec 27, 2023

  1. RAG Assemble
  • knowledge factory, can create different knowledge like pdf, docx, markdown, txt, csv, pptx, url.
from dbgpt.rag.knowledge.factory import KnowledgeFactory
knowledge = KnowledgeFactory.create(datasource="path/1.pdf", knowledge_type=KnowledgeType.DOCUMENT)

  • unit tests

  • rag assemblers

    • EmbeddingAssembler
    • SummaryAssembler
    • examples in examples/rag
    • unit tests
    file_path = "./docs/docs/awel.md"
    knowledge = KnowledgeFactory.from_file_path(file_path)
    embedding_model_path = "{your_embedding_model_path}"
    chunk_parameters = ChunkParameters(chunk_strategy="CHUNK_BY_SIZE")
    # get embedding assembler
    assembler = EmbeddingAssembler.load_from_knowledge(
        knowledge=knowledge,
        chunk_parameters=chunk_parameters,
        embedding_model=embedding_model_path,
    )
    assembler.persist()
    # get embeddings retriever
    retriever = assembler.as_retriever(3)
    chunks = await retriever.aretrieve_with_scores("RAG", 0.3)
    print(f"embedding rag example results:{chunks}")

  • rag chunk manager
    • ChunkStrategies
    • ChunkManager
  1. RAG Retrieve
  • retrievers, provide retrieve() and retrieve_with_score()
    • EmbeddingRetriever
    • DBStructRetriever
    • unit tests
from dbgpt.rag.retriever.embedding import EmbeddingRetriever
from dbgpt.storage.vector_store.connector import VectorStoreConnector

embedding_fn = embedding_factory.create(
      model_name=EMBEDDING_MODEL_CONFIG[CFG.EMBEDDING_MODEL]
)
vector_name = "test"
config = ChromaVectorConfig(name=vector_name, embedding_fn=embedding_fn)
vector_store_connector = VectorStoreConnector(
    vector_store_type=""Chroma"",
     vector_store_config=config,
)
embedding_retriever = EmbeddingRetriever(
        top_k=3, vector_store_connector=vector_store_connector
)
chunks = embedding_retriever.retrieve("your query text")
print(f"embedding retriever results:{[chunk.content for chunk in chunks]}")
  • extractors, can extract summary, title and keyword, etc.
    • SummaryExtractor
  • query rewrite
  • rerank
    • DefaultRanker
  1. Examples and Unit tests

  2. ChatKnowledge web add segmentation step
    image

Aries-ckt and others added 30 commits December 11, 2023 21:12
@csunny
Copy link
Collaborator

csunny commented Jan 2, 2024

Follow commands that need to be run. Please run the following command to install new pre-commit hooks

pre-commit install

Every time you execute the command git commit xxx it will automatically trigger make fmt and make test

And you can manually trigger git hooks through the command pre-commit run --all-files

web/tsconfig.json Outdated Show resolved Hide resolved
web/styles/globals.css Outdated Show resolved Hide resolved
csunny
csunny previously approved these changes Jan 2, 2024
Copy link
Collaborator

@csunny csunny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+

@csunny
Copy link
Collaborator

csunny commented Jan 2, 2024

(dbgpt_env) % python examples/rag/db_struct_rag_example.py
<class 'dbgpt.storage.vector_store.chroma_store.ChromaStore'>
Traceback (most recent call last):
  File "/Users/magic/workspace/github/eosphoros-ai/DB-GPT/examples/rag/db_struct_rag_example.py", line 47, in <module>
    vector_connector = VectorStoreConnector.from_default(
  File "/Users/magic/workspace/github/eosphoros-ai/DB-GPT/dbgpt/storage/vector_store/connector.py", line 60, in from_default
    return cls(vector_store_type, vector_store_config)
  File "/Users/magic/workspace/github/eosphoros-ai/DB-GPT/dbgpt/storage/vector_store/connector.py", line 43, in __init__
    self.client = self.connector_class(vector_store_config)
  File "/Users/magic/workspace/github/eosphoros-ai/DB-GPT/dbgpt/storage/vector_store/chroma_store.py", line 39, in __init__
    self.persist_dir = os.path.join(
  File "/Users/magic/miniconda3/envs/dbgpt_env/lib/python3.10/posixpath.py", line 76, in join
    a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not NoneType

csunny
csunny previously approved these changes Jan 2, 2024
Copy link
Collaborator

@csunny csunny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+

Copy link
Collaborator

@Aralhi Aralhi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+

Copy link
Collaborator

@csunny csunny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+

@csunny csunny merged commit 9ad70a2 into main Jan 3, 2024
4 checks passed
vshy108 pushed a commit to vshy108/DB-GPT that referenced this pull request Jan 18, 2024
vshy108 pushed a commit to vshy108/DB-GPT that referenced this pull request Feb 6, 2024
author penghou.ho <[email protected]> 1701341533 +0800
committer penghou.ho <[email protected]> 1707199703 +0800

parent 3f70da4
author penghou.ho <[email protected]> 1701341533 +0800
committer penghou.ho <[email protected]> 1707198697 +0800

parent 3f70da4
author penghou.ho <[email protected]> 1701341533 +0800
committer penghou.ho <[email protected]> 1707198521 +0800

Add requirements.txt

Create only necesasary tables

Remove reference info in chat completion result
Set disable_alembic_upgrade to True
Comment _initialize_awel
Comment mount_static_files
Fix torch.has_mps deprecated

Add API key

Comment unused API endpoints

Install rocksdict to enable DiskCacheStorage

Fix the chat_knowledge missing in chat_mode

Update requirements.txt

Re-enable awel and add api key check for simple_rag_example DAG

Merge main bdf9442

Disable disable_alembic_upgrade

Compile bitsandbytes from source and enable verbose

Tune the prompt of chat knowledge to only refer to context

Add the web static files and uncomment previous unused APIs

Add back routers

Enable KNOWLEDGE_CHAT_SHOW_RELATIONS

Display relation based on CFG.KNOWLEDGE_CHAT_SHOW_RELATIONS

Stop reference add to last_output if KNOWLEDGE_CHAT_SHOW_RELATIONS is false

Fix always no reference

Improve chinese prompts

Update requirements.txt

Improve prompt

Improve prompt

Fix prompt variable name

Use openhermes-2.5-mistral-7b.Q4_K_M.gguf

1. Fix the delete issue of LlamaCppModel
2. Disable verbose log
3. Update diskcache
4. Remove conda-pack

Update chinese prompt and process the model response

Extract result from varying tags

Add back missing content_matches and put tags regex into variable

Update english prompt and decide CANNOT_ANSWER based on language configuration

Add 3 new models entries and upgrade bitsandbytes

Add few chat templates

Update model conversation with fastchat code

Revert "Update model conversation with fastchat code"

This reverts commit a5dc4b5.

Revert "Add few chat templates"

This reverts commit e6b6c99.

Add OpenHermes-2.5-Mistral-7B chat template

Fix missing messages and offset in chat template

Update fschat

Remove model adapter debugging logs and added conversation template

Update chinese chat knowledge prompt

Avoid to save the long chat history messages

Update chinese chat knowledge prompt

Temporary workaround to make the GGUF file use different chat template

Use ADD_COLON_SINGLE instead of FALCON_CHAT for separator style

Allow no model_name in chat completion request

Use starling-lm-7b-alpha.Q5_K_M.gguf

Add empty string as system for openchat_3.5 chat template

Undo response regex in generate_streaming

refactor: Refactor storage and new serve template (eosphoros-ai#947)

feat(core): Add API authentication for serve template (eosphoros-ai#950)

ci: Add python unit test workflows (eosphoros-ai#954)

feat(model): Support Mixtral-8x7B (eosphoros-ai#959)

feat(core): Support multi round conversation operator (eosphoros-ai#986)

chore(build): Fix typo and new pre-commit config (eosphoros-ai#987)

feat(model): Support SOLAR-10.7B-Instruct-v1.0 (eosphoros-ai#1001)

refactor: RAG Refactor (eosphoros-ai#985)

Co-authored-by: Aralhi <[email protected]>
Co-authored-by: csunny <[email protected]>

Upgrade english prompt for chat knowledge
vshy108 pushed a commit to vshy108/DB-GPT that referenced this pull request Feb 13, 2024
author penghou.ho <[email protected]> 1701341533 +0800
committer penghou.ho <[email protected]> 1707199703 +0800

parent 3f70da4
author penghou.ho <[email protected]> 1701341533 +0800
committer penghou.ho <[email protected]> 1707198697 +0800

parent 3f70da4
author penghou.ho <[email protected]> 1701341533 +0800
committer penghou.ho <[email protected]> 1707198521 +0800

Add requirements.txt

Create only necesasary tables

Remove reference info in chat completion result
Set disable_alembic_upgrade to True
Comment _initialize_awel
Comment mount_static_files
Fix torch.has_mps deprecated

Add API key

Comment unused API endpoints

Install rocksdict to enable DiskCacheStorage

Fix the chat_knowledge missing in chat_mode

Update requirements.txt

Re-enable awel and add api key check for simple_rag_example DAG

Merge main bdf9442

Disable disable_alembic_upgrade

Compile bitsandbytes from source and enable verbose

Tune the prompt of chat knowledge to only refer to context

Add the web static files and uncomment previous unused APIs

Add back routers

Enable KNOWLEDGE_CHAT_SHOW_RELATIONS

Display relation based on CFG.KNOWLEDGE_CHAT_SHOW_RELATIONS

Stop reference add to last_output if KNOWLEDGE_CHAT_SHOW_RELATIONS is false

Fix always no reference

Improve chinese prompts

Update requirements.txt

Improve prompt

Improve prompt

Fix prompt variable name

Use openhermes-2.5-mistral-7b.Q4_K_M.gguf

1. Fix the delete issue of LlamaCppModel
2. Disable verbose log
3. Update diskcache
4. Remove conda-pack

Update chinese prompt and process the model response

Extract result from varying tags

Add back missing content_matches and put tags regex into variable

Update english prompt and decide CANNOT_ANSWER based on language configuration

Add 3 new models entries and upgrade bitsandbytes

Add few chat templates

Update model conversation with fastchat code

Revert "Update model conversation with fastchat code"

This reverts commit a5dc4b5.

Revert "Add few chat templates"

This reverts commit e6b6c99.

Add OpenHermes-2.5-Mistral-7B chat template

Fix missing messages and offset in chat template

Update fschat

Remove model adapter debugging logs and added conversation template

Update chinese chat knowledge prompt

Avoid to save the long chat history messages

Update chinese chat knowledge prompt

Temporary workaround to make the GGUF file use different chat template

Use ADD_COLON_SINGLE instead of FALCON_CHAT for separator style

Allow no model_name in chat completion request

Use starling-lm-7b-alpha.Q5_K_M.gguf

Add empty string as system for openchat_3.5 chat template

Undo response regex in generate_streaming

refactor: Refactor storage and new serve template (eosphoros-ai#947)

feat(core): Add API authentication for serve template (eosphoros-ai#950)

ci: Add python unit test workflows (eosphoros-ai#954)

feat(model): Support Mixtral-8x7B (eosphoros-ai#959)

feat(core): Support multi round conversation operator (eosphoros-ai#986)

chore(build): Fix typo and new pre-commit config (eosphoros-ai#987)

feat(model): Support SOLAR-10.7B-Instruct-v1.0 (eosphoros-ai#1001)

refactor: RAG Refactor (eosphoros-ai#985)

Co-authored-by: Aralhi <[email protected]>
Co-authored-by: csunny <[email protected]>

Upgrade english prompt for chat knowledge
vshy108 pushed a commit to vshy108/DB-GPT that referenced this pull request Feb 13, 2024
author penghou.ho <[email protected]> 1701341533 +0800
committer penghou.ho <[email protected]> 1707199703 +0800

parent 3f70da4
author penghou.ho <[email protected]> 1701341533 +0800
committer penghou.ho <[email protected]> 1707198697 +0800

parent 3f70da4
author penghou.ho <[email protected]> 1701341533 +0800
committer penghou.ho <[email protected]> 1707198521 +0800

Add requirements.txt

Create only necesasary tables

Remove reference info in chat completion result
Set disable_alembic_upgrade to True
Comment _initialize_awel
Comment mount_static_files
Fix torch.has_mps deprecated

Add API key

Comment unused API endpoints

Install rocksdict to enable DiskCacheStorage

Fix the chat_knowledge missing in chat_mode

Update requirements.txt

Re-enable awel and add api key check for simple_rag_example DAG

Merge main bdf9442

Disable disable_alembic_upgrade

Compile bitsandbytes from source and enable verbose

Tune the prompt of chat knowledge to only refer to context

Add the web static files and uncomment previous unused APIs

Add back routers

Enable KNOWLEDGE_CHAT_SHOW_RELATIONS

Display relation based on CFG.KNOWLEDGE_CHAT_SHOW_RELATIONS

Stop reference add to last_output if KNOWLEDGE_CHAT_SHOW_RELATIONS is false

Fix always no reference

Improve chinese prompts

Update requirements.txt

Improve prompt

Improve prompt

Fix prompt variable name

Use openhermes-2.5-mistral-7b.Q4_K_M.gguf

1. Fix the delete issue of LlamaCppModel
2. Disable verbose log
3. Update diskcache
4. Remove conda-pack

Update chinese prompt and process the model response

Extract result from varying tags

Add back missing content_matches and put tags regex into variable

Update english prompt and decide CANNOT_ANSWER based on language configuration

Add 3 new models entries and upgrade bitsandbytes

Add few chat templates

Update model conversation with fastchat code

Revert "Update model conversation with fastchat code"

This reverts commit a5dc4b5.

Revert "Add few chat templates"

This reverts commit e6b6c99.

Add OpenHermes-2.5-Mistral-7B chat template

Fix missing messages and offset in chat template

Update fschat

Remove model adapter debugging logs and added conversation template

Update chinese chat knowledge prompt

Avoid to save the long chat history messages

Update chinese chat knowledge prompt

Temporary workaround to make the GGUF file use different chat template

Use ADD_COLON_SINGLE instead of FALCON_CHAT for separator style

Allow no model_name in chat completion request

Use starling-lm-7b-alpha.Q5_K_M.gguf

Add empty string as system for openchat_3.5 chat template

Undo response regex in generate_streaming

refactor: Refactor storage and new serve template (eosphoros-ai#947)

feat(core): Add API authentication for serve template (eosphoros-ai#950)

ci: Add python unit test workflows (eosphoros-ai#954)

feat(model): Support Mixtral-8x7B (eosphoros-ai#959)

feat(core): Support multi round conversation operator (eosphoros-ai#986)

chore(build): Fix typo and new pre-commit config (eosphoros-ai#987)

feat(model): Support SOLAR-10.7B-Instruct-v1.0 (eosphoros-ai#1001)

refactor: RAG Refactor (eosphoros-ai#985)

Co-authored-by: Aralhi <[email protected]>
Co-authored-by: csunny <[email protected]>

Upgrade english prompt for chat knowledge
vshy108 pushed a commit to vshy108/DB-GPT that referenced this pull request Feb 13, 2024
author penghou.ho <[email protected]> 1701341533 +0800
committer penghou.ho <[email protected]> 1707199703 +0800

parent 3f70da4
author penghou.ho <[email protected]> 1701341533 +0800
committer penghou.ho <[email protected]> 1707198697 +0800

parent 3f70da4
author penghou.ho <[email protected]> 1701341533 +0800
committer penghou.ho <[email protected]> 1707198521 +0800

Add requirements.txt

Create only necesasary tables

Remove reference info in chat completion result
Set disable_alembic_upgrade to True
Comment _initialize_awel
Comment mount_static_files
Fix torch.has_mps deprecated

Add API key

Comment unused API endpoints

Install rocksdict to enable DiskCacheStorage

Fix the chat_knowledge missing in chat_mode

Update requirements.txt

Re-enable awel and add api key check for simple_rag_example DAG

Merge main bdf9442

Disable disable_alembic_upgrade

Compile bitsandbytes from source and enable verbose

Tune the prompt of chat knowledge to only refer to context

Add the web static files and uncomment previous unused APIs

Add back routers

Enable KNOWLEDGE_CHAT_SHOW_RELATIONS

Display relation based on CFG.KNOWLEDGE_CHAT_SHOW_RELATIONS

Stop reference add to last_output if KNOWLEDGE_CHAT_SHOW_RELATIONS is false

Fix always no reference

Improve chinese prompts

Update requirements.txt

Improve prompt

Improve prompt

Fix prompt variable name

Use openhermes-2.5-mistral-7b.Q4_K_M.gguf

1. Fix the delete issue of LlamaCppModel
2. Disable verbose log
3. Update diskcache
4. Remove conda-pack

Update chinese prompt and process the model response

Extract result from varying tags

Add back missing content_matches and put tags regex into variable

Update english prompt and decide CANNOT_ANSWER based on language configuration

Add 3 new models entries and upgrade bitsandbytes

Add few chat templates

Update model conversation with fastchat code

Revert "Update model conversation with fastchat code"

This reverts commit a5dc4b5.

Revert "Add few chat templates"

This reverts commit e6b6c99.

Add OpenHermes-2.5-Mistral-7B chat template

Fix missing messages and offset in chat template

Update fschat

Remove model adapter debugging logs and added conversation template

Update chinese chat knowledge prompt

Avoid to save the long chat history messages

Update chinese chat knowledge prompt

Temporary workaround to make the GGUF file use different chat template

Use ADD_COLON_SINGLE instead of FALCON_CHAT for separator style

Allow no model_name in chat completion request

Use starling-lm-7b-alpha.Q5_K_M.gguf

Add empty string as system for openchat_3.5 chat template

Undo response regex in generate_streaming

refactor: Refactor storage and new serve template (eosphoros-ai#947)

feat(core): Add API authentication for serve template (eosphoros-ai#950)

ci: Add python unit test workflows (eosphoros-ai#954)

feat(model): Support Mixtral-8x7B (eosphoros-ai#959)

feat(core): Support multi round conversation operator (eosphoros-ai#986)

chore(build): Fix typo and new pre-commit config (eosphoros-ai#987)

feat(model): Support SOLAR-10.7B-Instruct-v1.0 (eosphoros-ai#1001)

refactor: RAG Refactor (eosphoros-ai#985)

Co-authored-by: Aralhi <[email protected]>
Co-authored-by: csunny <[email protected]>

Upgrade english prompt for chat knowledge
Hopshine pushed a commit to Hopshine/DB-GPT that referenced this pull request Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal DB-GPT internal flag(chore|ci|refactor|test)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants