diff --git a/.doctrees/apis/components/_autosummary/components.agent.react.doctree b/.doctrees/apis/components/_autosummary/components.agent.react.doctree
index 486116f50..7e1317500 100644
Binary files a/.doctrees/apis/components/_autosummary/components.agent.react.doctree and b/.doctrees/apis/components/_autosummary/components.agent.react.doctree differ
diff --git a/.doctrees/apis/components/_autosummary/components.api_client.anthropic_client.doctree b/.doctrees/apis/components/_autosummary/components.api_client.anthropic_client.doctree
deleted file mode 100644
index 0101f44dc..000000000
Binary files a/.doctrees/apis/components/_autosummary/components.api_client.anthropic_client.doctree and /dev/null differ
diff --git a/.doctrees/apis/components/_autosummary/components.api_client.google_client.doctree b/.doctrees/apis/components/_autosummary/components.api_client.google_client.doctree
deleted file mode 100644
index d966f79c3..000000000
Binary files a/.doctrees/apis/components/_autosummary/components.api_client.google_client.doctree and /dev/null differ
diff --git a/.doctrees/apis/components/_autosummary/components.api_client.groq_client.doctree b/.doctrees/apis/components/_autosummary/components.api_client.groq_client.doctree
deleted file mode 100644
index 93adb0a35..000000000
Binary files a/.doctrees/apis/components/_autosummary/components.api_client.groq_client.doctree and /dev/null differ
diff --git a/.doctrees/apis/components/_autosummary/components.api_client.openai_client.doctree b/.doctrees/apis/components/_autosummary/components.api_client.openai_client.doctree
deleted file mode 100644
index c99d7ede3..000000000
Binary files a/.doctrees/apis/components/_autosummary/components.api_client.openai_client.doctree and /dev/null differ
diff --git a/.doctrees/apis/components/_autosummary/components.api_client.transformers_client.doctree b/.doctrees/apis/components/_autosummary/components.api_client.transformers_client.doctree
deleted file mode 100644
index 4f62a145d..000000000
Binary files a/.doctrees/apis/components/_autosummary/components.api_client.transformers_client.doctree and /dev/null differ
diff --git a/.doctrees/apis/components/_autosummary/components.data_process.data_components.doctree b/.doctrees/apis/components/_autosummary/components.data_process.data_components.doctree
index 99f3b41cc..eecace9b2 100644
Binary files a/.doctrees/apis/components/_autosummary/components.data_process.data_components.doctree and b/.doctrees/apis/components/_autosummary/components.data_process.data_components.doctree differ
diff --git a/.doctrees/apis/components/_autosummary/components.data_process.document_splitter.doctree b/.doctrees/apis/components/_autosummary/components.data_process.document_splitter.doctree
deleted file mode 100644
index 31fc48856..000000000
Binary files a/.doctrees/apis/components/_autosummary/components.data_process.document_splitter.doctree and /dev/null differ
diff --git a/.doctrees/apis/components/_autosummary/components.data_process.text_splitter.doctree b/.doctrees/apis/components/_autosummary/components.data_process.text_splitter.doctree
index 72d5ca295..71199436f 100644
Binary files a/.doctrees/apis/components/_autosummary/components.data_process.text_splitter.doctree and b/.doctrees/apis/components/_autosummary/components.data_process.text_splitter.doctree differ
diff --git a/.doctrees/apis/components/_autosummary/components.memory.memory.doctree b/.doctrees/apis/components/_autosummary/components.memory.memory.doctree
index 562c283b1..96aed50d6 100644
Binary files a/.doctrees/apis/components/_autosummary/components.memory.memory.doctree and b/.doctrees/apis/components/_autosummary/components.memory.memory.doctree differ
diff --git a/.doctrees/apis/components/_autosummary/components.model_client.anthropic_client.doctree b/.doctrees/apis/components/_autosummary/components.model_client.anthropic_client.doctree
deleted file mode 100644
index 6d11e536e..000000000
Binary files a/.doctrees/apis/components/_autosummary/components.model_client.anthropic_client.doctree and /dev/null differ
diff --git a/.doctrees/apis/components/_autosummary/components.model_client.cohere_client.doctree b/.doctrees/apis/components/_autosummary/components.model_client.cohere_client.doctree
deleted file mode 100644
index 031ef2d57..000000000
Binary files a/.doctrees/apis/components/_autosummary/components.model_client.cohere_client.doctree and /dev/null differ
diff --git a/.doctrees/apis/components/_autosummary/components.model_client.google_client.doctree b/.doctrees/apis/components/_autosummary/components.model_client.google_client.doctree
deleted file mode 100644
index db9e06aa0..000000000
Binary files a/.doctrees/apis/components/_autosummary/components.model_client.google_client.doctree and /dev/null differ
diff --git a/.doctrees/apis/components/_autosummary/components.model_client.groq_client.doctree b/.doctrees/apis/components/_autosummary/components.model_client.groq_client.doctree
deleted file mode 100644
index 8e5e20c1e..000000000
Binary files a/.doctrees/apis/components/_autosummary/components.model_client.groq_client.doctree and /dev/null differ
diff --git a/.doctrees/apis/components/_autosummary/components.model_client.openai_client.doctree b/.doctrees/apis/components/_autosummary/components.model_client.openai_client.doctree
deleted file mode 100644
index b1914bc94..000000000
Binary files a/.doctrees/apis/components/_autosummary/components.model_client.openai_client.doctree and /dev/null differ
diff --git a/.doctrees/apis/components/_autosummary/components.model_client.transformers_client.doctree b/.doctrees/apis/components/_autosummary/components.model_client.transformers_client.doctree
index 8a4e8a608..91b1092d9 100644
Binary files a/.doctrees/apis/components/_autosummary/components.model_client.transformers_client.doctree and b/.doctrees/apis/components/_autosummary/components.model_client.transformers_client.doctree differ
diff --git a/.doctrees/apis/components/_autosummary/components.model_client.utils.doctree b/.doctrees/apis/components/_autosummary/components.model_client.utils.doctree
index 0c99dc29a..5d89079dc 100644
Binary files a/.doctrees/apis/components/_autosummary/components.model_client.utils.doctree and b/.doctrees/apis/components/_autosummary/components.model_client.utils.doctree differ
diff --git a/.doctrees/apis/components/_autosummary/components.output_parsers.outputs.doctree b/.doctrees/apis/components/_autosummary/components.output_parsers.outputs.doctree
index 9e42d59d6..01db20189 100644
Binary files a/.doctrees/apis/components/_autosummary/components.output_parsers.outputs.doctree and b/.doctrees/apis/components/_autosummary/components.output_parsers.outputs.doctree differ
diff --git a/.doctrees/apis/components/_autosummary/components.reasoning.chain_of_thought.doctree b/.doctrees/apis/components/_autosummary/components.reasoning.chain_of_thought.doctree
index 62a2750f5..23cdf92b8 100644
Binary files a/.doctrees/apis/components/_autosummary/components.reasoning.chain_of_thought.doctree and b/.doctrees/apis/components/_autosummary/components.reasoning.chain_of_thought.doctree differ
diff --git a/.doctrees/apis/components/_autosummary/components.retriever.bm25_retriever.doctree b/.doctrees/apis/components/_autosummary/components.retriever.bm25_retriever.doctree
index 02f12493b..38e2ae705 100644
Binary files a/.doctrees/apis/components/_autosummary/components.retriever.bm25_retriever.doctree and b/.doctrees/apis/components/_autosummary/components.retriever.bm25_retriever.doctree differ
diff --git a/.doctrees/apis/components/_autosummary/components.retriever.faiss_retriever.doctree b/.doctrees/apis/components/_autosummary/components.retriever.faiss_retriever.doctree
deleted file mode 100644
index e4ddf88eb..000000000
Binary files a/.doctrees/apis/components/_autosummary/components.retriever.faiss_retriever.doctree and /dev/null differ
diff --git a/.doctrees/apis/components/_autosummary/components.retriever.llm_retriever.doctree b/.doctrees/apis/components/_autosummary/components.retriever.llm_retriever.doctree
index 31d5bed98..89a03c356 100644
Binary files a/.doctrees/apis/components/_autosummary/components.retriever.llm_retriever.doctree and b/.doctrees/apis/components/_autosummary/components.retriever.llm_retriever.doctree differ
diff --git a/.doctrees/apis/components/_autosummary/components.retriever.postgres_retriever.doctree b/.doctrees/apis/components/_autosummary/components.retriever.postgres_retriever.doctree
deleted file mode 100644
index b25e95c96..000000000
Binary files a/.doctrees/apis/components/_autosummary/components.retriever.postgres_retriever.doctree and /dev/null differ
diff --git a/.doctrees/apis/components/_autosummary/components.retriever.reranker_retriever.doctree b/.doctrees/apis/components/_autosummary/components.retriever.reranker_retriever.doctree
index 77d6e94a9..21b5bbf42 100644
Binary files a/.doctrees/apis/components/_autosummary/components.retriever.reranker_retriever.doctree and b/.doctrees/apis/components/_autosummary/components.retriever.reranker_retriever.doctree differ
diff --git a/.doctrees/apis/components/components.agent.doctree b/.doctrees/apis/components/components.agent.doctree
index d0842cd39..4a77c50fa 100644
Binary files a/.doctrees/apis/components/components.agent.doctree and b/.doctrees/apis/components/components.agent.doctree differ
diff --git a/.doctrees/apis/components/components.data_process.data_components.doctree b/.doctrees/apis/components/components.data_process.data_components.doctree
index a60821a00..9bd8b4983 100644
Binary files a/.doctrees/apis/components/components.data_process.data_components.doctree and b/.doctrees/apis/components/components.data_process.data_components.doctree differ
diff --git a/.doctrees/apis/components/components.data_process.doctree b/.doctrees/apis/components/components.data_process.doctree
index 9e4e3e709..0b77d57df 100644
Binary files a/.doctrees/apis/components/components.data_process.doctree and b/.doctrees/apis/components/components.data_process.doctree differ
diff --git a/.doctrees/apis/components/components.data_process.document_splitter.doctree b/.doctrees/apis/components/components.data_process.document_splitter.doctree
deleted file mode 100644
index a0628bd34..000000000
Binary files a/.doctrees/apis/components/components.data_process.document_splitter.doctree and /dev/null differ
diff --git a/.doctrees/apis/components/components.data_process.text_splitter.doctree b/.doctrees/apis/components/components.data_process.text_splitter.doctree
index d8b87e145..623be3364 100644
Binary files a/.doctrees/apis/components/components.data_process.text_splitter.doctree and b/.doctrees/apis/components/components.data_process.text_splitter.doctree differ
diff --git a/.doctrees/apis/components/components.memory.doctree b/.doctrees/apis/components/components.memory.doctree
index 7ec837428..1c76a9bbf 100644
Binary files a/.doctrees/apis/components/components.memory.doctree and b/.doctrees/apis/components/components.memory.doctree differ
diff --git a/.doctrees/apis/components/components.memory.memory.doctree b/.doctrees/apis/components/components.memory.memory.doctree
index 3d720adc9..01980cec3 100644
Binary files a/.doctrees/apis/components/components.memory.memory.doctree and b/.doctrees/apis/components/components.memory.memory.doctree differ
diff --git a/.doctrees/apis/components/components.model_client.doctree b/.doctrees/apis/components/components.model_client.doctree
index 01456837e..cde8ee131 100644
Binary files a/.doctrees/apis/components/components.model_client.doctree and b/.doctrees/apis/components/components.model_client.doctree differ
diff --git a/.doctrees/apis/components/components.model_client.utils.doctree b/.doctrees/apis/components/components.model_client.utils.doctree
index c257171ce..f16206eb5 100644
Binary files a/.doctrees/apis/components/components.model_client.utils.doctree and b/.doctrees/apis/components/components.model_client.utils.doctree differ
diff --git a/.doctrees/apis/components/components.output_parsers.doctree b/.doctrees/apis/components/components.output_parsers.doctree
index eca769ce9..1576c9da4 100644
Binary files a/.doctrees/apis/components/components.output_parsers.doctree and b/.doctrees/apis/components/components.output_parsers.doctree differ
diff --git a/.doctrees/apis/components/components.reasoning.doctree b/.doctrees/apis/components/components.reasoning.doctree
index 7175f30af..84a200fce 100644
Binary files a/.doctrees/apis/components/components.reasoning.doctree and b/.doctrees/apis/components/components.reasoning.doctree differ
diff --git a/.doctrees/apis/components/components.retriever.doctree b/.doctrees/apis/components/components.retriever.doctree
index 97458929b..6c27b101d 100644
Binary files a/.doctrees/apis/components/components.retriever.doctree and b/.doctrees/apis/components/components.retriever.doctree differ
diff --git a/.doctrees/apis/components/index.doctree b/.doctrees/apis/components/index.doctree
index a5fec8f50..77de0a55b 100644
Binary files a/.doctrees/apis/components/index.doctree and b/.doctrees/apis/components/index.doctree differ
diff --git a/.doctrees/apis/core/core.base_data_class.doctree b/.doctrees/apis/core/core.base_data_class.doctree
index af9aa2076..485abdfdf 100644
Binary files a/.doctrees/apis/core/core.base_data_class.doctree and b/.doctrees/apis/core/core.base_data_class.doctree differ
diff --git a/.doctrees/apis/core/core.component.doctree b/.doctrees/apis/core/core.component.doctree
index 525540494..e8e99c73d 100644
Binary files a/.doctrees/apis/core/core.component.doctree and b/.doctrees/apis/core/core.component.doctree differ
diff --git a/.doctrees/apis/core/core.data_components.doctree b/.doctrees/apis/core/core.data_components.doctree
deleted file mode 100644
index 623085f24..000000000
Binary files a/.doctrees/apis/core/core.data_components.doctree and /dev/null differ
diff --git a/.doctrees/apis/core/core.db.doctree b/.doctrees/apis/core/core.db.doctree
index 79f65e847..feaeb5c5d 100644
Binary files a/.doctrees/apis/core/core.db.doctree and b/.doctrees/apis/core/core.db.doctree differ
diff --git a/.doctrees/apis/core/core.default_prompt_template.doctree b/.doctrees/apis/core/core.default_prompt_template.doctree
index 0fa4b0eb8..797421bbf 100644
Binary files a/.doctrees/apis/core/core.default_prompt_template.doctree and b/.doctrees/apis/core/core.default_prompt_template.doctree differ
diff --git a/.doctrees/apis/core/core.document_splitter.doctree b/.doctrees/apis/core/core.document_splitter.doctree
deleted file mode 100644
index 3a4536687..000000000
Binary files a/.doctrees/apis/core/core.document_splitter.doctree and /dev/null differ
diff --git a/.doctrees/apis/core/core.embedder.doctree b/.doctrees/apis/core/core.embedder.doctree
index f550d0f7f..f1a7a205f 100644
Binary files a/.doctrees/apis/core/core.embedder.doctree and b/.doctrees/apis/core/core.embedder.doctree differ
diff --git a/.doctrees/apis/core/core.func_tool.doctree b/.doctrees/apis/core/core.func_tool.doctree
index d422c5421..d2b248afb 100644
Binary files a/.doctrees/apis/core/core.func_tool.doctree and b/.doctrees/apis/core/core.func_tool.doctree differ
diff --git a/.doctrees/apis/core/core.functional.doctree b/.doctrees/apis/core/core.functional.doctree
index 8909f3904..662c4fc36 100644
Binary files a/.doctrees/apis/core/core.functional.doctree and b/.doctrees/apis/core/core.functional.doctree differ
diff --git a/.doctrees/apis/core/core.generator.doctree b/.doctrees/apis/core/core.generator.doctree
index 81796e752..1b471549a 100644
Binary files a/.doctrees/apis/core/core.generator.doctree and b/.doctrees/apis/core/core.generator.doctree differ
diff --git a/.doctrees/apis/core/core.memory.doctree b/.doctrees/apis/core/core.memory.doctree
deleted file mode 100644
index fa7082323..000000000
Binary files a/.doctrees/apis/core/core.memory.doctree and /dev/null differ
diff --git a/.doctrees/apis/core/core.model_client.doctree b/.doctrees/apis/core/core.model_client.doctree
index 3efcf212b..57ae74bd1 100644
Binary files a/.doctrees/apis/core/core.model_client.doctree and b/.doctrees/apis/core/core.model_client.doctree differ
diff --git a/.doctrees/apis/core/core.parameter.doctree b/.doctrees/apis/core/core.parameter.doctree
index 911340e82..02c26fc4d 100644
Binary files a/.doctrees/apis/core/core.parameter.doctree and b/.doctrees/apis/core/core.parameter.doctree differ
diff --git a/.doctrees/apis/core/core.prompt_builder.doctree b/.doctrees/apis/core/core.prompt_builder.doctree
index 8e21d38e9..20e521cd7 100644
Binary files a/.doctrees/apis/core/core.prompt_builder.doctree and b/.doctrees/apis/core/core.prompt_builder.doctree differ
diff --git a/.doctrees/apis/core/core.retriever.doctree b/.doctrees/apis/core/core.retriever.doctree
index bbeb3bd37..3940ce780 100644
Binary files a/.doctrees/apis/core/core.retriever.doctree and b/.doctrees/apis/core/core.retriever.doctree differ
diff --git a/.doctrees/apis/core/core.string_parser.doctree b/.doctrees/apis/core/core.string_parser.doctree
index 4b3bc0905..a4a037ca2 100644
Binary files a/.doctrees/apis/core/core.string_parser.doctree and b/.doctrees/apis/core/core.string_parser.doctree differ
diff --git a/.doctrees/apis/core/core.tokenizer.doctree b/.doctrees/apis/core/core.tokenizer.doctree
index 31b616991..c3f0ce168 100644
Binary files a/.doctrees/apis/core/core.tokenizer.doctree and b/.doctrees/apis/core/core.tokenizer.doctree differ
diff --git a/.doctrees/apis/core/core.tool_manager.doctree b/.doctrees/apis/core/core.tool_manager.doctree
index 69f24c968..0fa4a5738 100644
Binary files a/.doctrees/apis/core/core.tool_manager.doctree and b/.doctrees/apis/core/core.tool_manager.doctree differ
diff --git a/.doctrees/apis/core/core.types.doctree b/.doctrees/apis/core/core.types.doctree
index c263c906d..0cd02a67e 100644
Binary files a/.doctrees/apis/core/core.types.doctree and b/.doctrees/apis/core/core.types.doctree differ
diff --git a/.doctrees/apis/core/index.doctree b/.doctrees/apis/core/index.doctree
index f2fc4b8ca..4e1a1b016 100644
Binary files a/.doctrees/apis/core/index.doctree and b/.doctrees/apis/core/index.doctree differ
diff --git a/.doctrees/apis/eval/eval.answer_match_acc.doctree b/.doctrees/apis/eval/eval.answer_match_acc.doctree
index 9d627dd56..29f279755 100644
Binary files a/.doctrees/apis/eval/eval.answer_match_acc.doctree and b/.doctrees/apis/eval/eval.answer_match_acc.doctree differ
diff --git a/.doctrees/apis/eval/eval.evaluators.doctree b/.doctrees/apis/eval/eval.evaluators.doctree
deleted file mode 100644
index 49b6b37a6..000000000
Binary files a/.doctrees/apis/eval/eval.evaluators.doctree and /dev/null differ
diff --git a/.doctrees/apis/eval/eval.llm_as_judge.doctree b/.doctrees/apis/eval/eval.llm_as_judge.doctree
index 1cb9617ad..0abea0b37 100644
Binary files a/.doctrees/apis/eval/eval.llm_as_judge.doctree and b/.doctrees/apis/eval/eval.llm_as_judge.doctree differ
diff --git a/.doctrees/apis/eval/eval.retriever_recall.doctree b/.doctrees/apis/eval/eval.retriever_recall.doctree
index cead7f31c..26174bf0b 100644
Binary files a/.doctrees/apis/eval/eval.retriever_recall.doctree and b/.doctrees/apis/eval/eval.retriever_recall.doctree differ
diff --git a/.doctrees/apis/eval/eval.retriever_relevance.doctree b/.doctrees/apis/eval/eval.retriever_relevance.doctree
index 867bd209f..851131bc5 100644
Binary files a/.doctrees/apis/eval/eval.retriever_relevance.doctree and b/.doctrees/apis/eval/eval.retriever_relevance.doctree differ
diff --git a/.doctrees/apis/index.doctree b/.doctrees/apis/index.doctree
index d64381639..4cdadf9ac 100644
Binary files a/.doctrees/apis/index.doctree and b/.doctrees/apis/index.doctree differ
diff --git a/.doctrees/apis/optim/optim.few_shot_optimizer.doctree b/.doctrees/apis/optim/optim.few_shot_optimizer.doctree
index a5008e8ec..3a487c5dd 100644
Binary files a/.doctrees/apis/optim/optim.few_shot_optimizer.doctree and b/.doctrees/apis/optim/optim.few_shot_optimizer.doctree differ
diff --git a/.doctrees/apis/optim/optim.llm_augment.doctree b/.doctrees/apis/optim/optim.llm_augment.doctree
index d6eebc969..6adb43c92 100644
Binary files a/.doctrees/apis/optim/optim.llm_augment.doctree and b/.doctrees/apis/optim/optim.llm_augment.doctree differ
diff --git a/.doctrees/apis/optim/optim.llm_optimizer.doctree b/.doctrees/apis/optim/optim.llm_optimizer.doctree
index 391a08565..5c4cf30b1 100644
Binary files a/.doctrees/apis/optim/optim.llm_optimizer.doctree and b/.doctrees/apis/optim/optim.llm_optimizer.doctree differ
diff --git a/.doctrees/apis/optim/optim.optimizer.doctree b/.doctrees/apis/optim/optim.optimizer.doctree
index 89db50769..259f0b5b9 100644
Binary files a/.doctrees/apis/optim/optim.optimizer.doctree and b/.doctrees/apis/optim/optim.optimizer.doctree differ
diff --git a/.doctrees/apis/optim/optim.sampler.doctree b/.doctrees/apis/optim/optim.sampler.doctree
index 3de5bd607..b97437789 100644
Binary files a/.doctrees/apis/optim/optim.sampler.doctree and b/.doctrees/apis/optim/optim.sampler.doctree differ
diff --git a/.doctrees/apis/tracing/tracing.decorators.doctree b/.doctrees/apis/tracing/tracing.decorators.doctree
index 5dace6b6d..9417f1e1f 100644
Binary files a/.doctrees/apis/tracing/tracing.decorators.doctree and b/.doctrees/apis/tracing/tracing.decorators.doctree differ
diff --git a/.doctrees/apis/tracing/tracing.generator_call_logger.doctree b/.doctrees/apis/tracing/tracing.generator_call_logger.doctree
index f4193fec8..c3597174d 100644
Binary files a/.doctrees/apis/tracing/tracing.generator_call_logger.doctree and b/.doctrees/apis/tracing/tracing.generator_call_logger.doctree differ
diff --git a/.doctrees/apis/tracing/tracing.generator_state_logger.doctree b/.doctrees/apis/tracing/tracing.generator_state_logger.doctree
index cc7bc5c3c..c9391cfe9 100644
Binary files a/.doctrees/apis/tracing/tracing.generator_state_logger.doctree and b/.doctrees/apis/tracing/tracing.generator_state_logger.doctree differ
diff --git a/.doctrees/apis/utils/index.doctree b/.doctrees/apis/utils/index.doctree
index adbdb1a82..45d9eaeef 100644
Binary files a/.doctrees/apis/utils/index.doctree and b/.doctrees/apis/utils/index.doctree differ
diff --git a/.doctrees/apis/utils/utils.config.doctree b/.doctrees/apis/utils/utils.config.doctree
index cff12b7f0..7c0075abd 100644
Binary files a/.doctrees/apis/utils/utils.config.doctree and b/.doctrees/apis/utils/utils.config.doctree differ
diff --git a/.doctrees/apis/utils/utils.file_io.doctree b/.doctrees/apis/utils/utils.file_io.doctree
index c7a41d7ae..a664ab1a3 100644
Binary files a/.doctrees/apis/utils/utils.file_io.doctree and b/.doctrees/apis/utils/utils.file_io.doctree differ
diff --git a/.doctrees/apis/utils/utils.lazy_import.doctree b/.doctrees/apis/utils/utils.lazy_import.doctree
index b4706b362..527f3f890 100644
Binary files a/.doctrees/apis/utils/utils.lazy_import.doctree and b/.doctrees/apis/utils/utils.lazy_import.doctree differ
diff --git a/.doctrees/apis/utils/utils.logger.doctree b/.doctrees/apis/utils/utils.logger.doctree
index f4dec1c27..abb7d6eb4 100644
Binary files a/.doctrees/apis/utils/utils.logger.doctree and b/.doctrees/apis/utils/utils.logger.doctree differ
diff --git a/.doctrees/apis/utils/utils.registry.doctree b/.doctrees/apis/utils/utils.registry.doctree
index 2c9b5ea54..7deb99787 100644
Binary files a/.doctrees/apis/utils/utils.registry.doctree and b/.doctrees/apis/utils/utils.registry.doctree differ
diff --git a/.doctrees/apis/utils/utils.serialization.doctree b/.doctrees/apis/utils/utils.serialization.doctree
index f8efa1c1d..7aa4c32e5 100644
Binary files a/.doctrees/apis/utils/utils.serialization.doctree and b/.doctrees/apis/utils/utils.serialization.doctree differ
diff --git a/.doctrees/apis/utils/utils.setup_env.doctree b/.doctrees/apis/utils/utils.setup_env.doctree
index d6dc1b86e..eb4abbdc4 100644
Binary files a/.doctrees/apis/utils/utils.setup_env.doctree and b/.doctrees/apis/utils/utils.setup_env.doctree differ
diff --git a/.doctrees/developer_notes/component.doctree b/.doctrees/developer_notes/component.doctree
index 6be9eea90..1f9dbd195 100644
Binary files a/.doctrees/developer_notes/component.doctree and b/.doctrees/developer_notes/component.doctree differ
diff --git a/.doctrees/developer_notes/db.doctree b/.doctrees/developer_notes/db.doctree
index ab705c8d2..f013ab8c9 100644
Binary files a/.doctrees/developer_notes/db.doctree and b/.doctrees/developer_notes/db.doctree differ
diff --git a/.doctrees/developer_notes/generator.doctree b/.doctrees/developer_notes/generator.doctree
index 1bdb32220..c734dfbdd 100644
Binary files a/.doctrees/developer_notes/generator.doctree and b/.doctrees/developer_notes/generator.doctree differ
diff --git a/.doctrees/environment.pickle b/.doctrees/environment.pickle
index b88e6e2af..b7788bc51 100644
Binary files a/.doctrees/environment.pickle and b/.doctrees/environment.pickle differ
diff --git a/.doctrees/get_started/installation.doctree b/.doctrees/get_started/installation.doctree
index a1c4e8944..70f2a4331 100644
Binary files a/.doctrees/get_started/installation.doctree and b/.doctrees/get_started/installation.doctree differ
diff --git a/_images/database.png b/_images/database.png
deleted file mode 100644
index b7903a894..000000000
Binary files a/_images/database.png and /dev/null differ
diff --git a/_modules/components/agent/react.html b/_modules/components/agent/react.html
index 646a03811..eba7485ed 100644
--- a/_modules/components/agent/react.html
+++ b/_modules/components/agent/react.html
@@ -29,7 +29,7 @@
-
+
@@ -499,7 +499,7 @@
Source code for components.agent.react
-[docs]
+[docs]classReActAgent(Component):__doc__=r"""ReActAgent uses generator as a planner that runs multiple and sequential functional call steps to generate the final response.
@@ -575,7 +575,7 @@
[docs]classTextSplitter(Component):
-"""
+""" Text Splitter for Chunking Documents ``TextSplitter`` first utilizes ``split_by`` to specify the text-splitting criterion and breaks the long text into smaller texts.
@@ -467,11 +460,11 @@
Source code for components.data_process.text_splitter
**Splitting Types**
- ``TextSplitter`` supports 2 types of splitting.
-
+ ``TextSplitter`` supports 2 types of splitting.
+ * **Type 1:** Specify the exact text splitting point such as space<" "> and periods<".">. It is intuitive, for example, split_by "word":
- ::
+ :: "Hello, world!" -> ["Hello, " ,"world!"]
@@ -485,7 +478,7 @@
Source code for components.data_process.text_splitter
Tokenizer reflects the real token numbers the models take in and helps the developers control budgets.
**Definitions**
-
+ * **split_by** specifies the split rule, i.e. the smallest unit during splitting. We support ``"word"``, ``"sentence"``, ``"page"``, ``"passage"``, and ``"token"``. The splitter utilizes the corresponding separator from the ``SEPARATORS`` dictionary. For Type 1 splitting, we apply ``Python str.split()`` to break the text.
@@ -494,16 +487,16 @@
Source code for components.data_process.text_splitter
.. note::
For option ``token``, its separator is "" because we directly split by a tokenizer, instead of text point.
- * **chunk_size** is the the maximum number of units in each chunk.
+ * **chunk_size** is the the maximum number of units in each chunk. * **chunk_overlap** is the number of units that each chunk should overlap. Including context at the borders prevents sudden meaning shift in text between sentences/context, especially in sentiment analysis.
-
+ * **Splitting Details**
- Type 1:
- The ``TextSplitter`` utilizes Python's ``str.split(separator)`` method.
- Developers can refer to
-
+ Type 1:
+ The ``TextSplitter`` utilizes Python's ``str.split(separator)`` method.
+ Developers can refer to
+ .. code-block:: none {
@@ -513,30 +506,30 @@
Source code for components.data_process.text_splitter
"sentence": "."
} for exact points of text division.
-
+ .. note:: Developers need to determine how to assign text to each data chunk for the embedding and retrieval tasks. Type 2: We implement a tokenizer using ``cl100k_base`` encoding that aligns with how models see text in the form of tokens. E.g. "tiktoken is great!" -> ["t", "ik", "token", " is", " great", "!"] This helps developers control the token usage and budget better.
-
+ * **Merge Details** Type 1/Type 2 create a list of split texts. ``TextSplitter`` then reattaches the specified separator to each piece of the split text, except for the last segment. This approach maintains the original spacing and punctuation, which is critical in contexts like natural language processing where text formatting can impact interpretations and outcomes. E.g. "hello world!" split by "word" will be kept as "hello " and "world!"
-
+ * **Customization**
- You can also customize the ``SEPARATORS``. For example, by defining ``SEPARATORS`` = {"question": "?"} and setting ``split_by`` = "question", the document will be split at each ``?``, ideal for processing text structured
+ You can also customize the ``SEPARATORS``. For example, by defining ``SEPARATORS`` = {"question": "?"} and setting ``split_by`` = "question", the document will be split at each ``?``, ideal for processing text structured as a series of questions. If you need to customize :class:`tokenizer <lightrag.core.tokenizer.Tokenizer>`, please check `Reference <https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb>`_.
-
+ * **Integration with Other Document Types** This functionality is ideal for segmenting texts into sentences, words, pages, or passages, which can then be processed further for NLP applications. For **PDFs**, developers will need to extract the text before using the splitter. Libraries like ``PyPDF2`` or ``PDFMiner`` can be utilized for this purpose. ``LightRAG``'s future implementations will introduce splitters for ``JSON``, ``HTML``, ``markdown``, and ``code``.
-
+ Example:
-
+ .. code-block:: python from lightrag.components.data_process.text_splitter import TextSplitter
@@ -566,20 +559,19 @@
Source code for components.data_process.text_splitter
# Document(id=ca0af45b-4f88-49b5-97db-163da9868ea4, text='text. Even more text to ', meta_data=None, vector=[], parent_doc_id=doc1, order=1, score=None)
# Document(id=e7b617b2-3927-4248-afce-ec0fc247ac8b, text='to illustrate.', meta_data=None, vector=[], parent_doc_id=doc1, order=2, score=None) """
-
def__init__(self,split_by:Literal["word","sentence","page","passage","token"]="word",chunk_size:int=DEFAULT_CHUNK_SIZE,chunk_overlap:int=DEFAULT_CHUNK_OVERLAP,
- batch_size:int=1000,
+ batch_size:int=1000):""" Initializes the TextSplitter with the specified parameters for text splitting. Args:
- split_by (str): The specific criterion to use for splitting the text.
- Valid options are 'word' to split by ' ', 'sentence' to split by '.',
+ split_by (str): The specific criterion to use for splitting the text.
+ Valid options are 'word' to split by ' ', 'sentence' to split by '.', 'page' to split by '\\f', 'passage' to split by '\\n\\n'. chunk_size (int): The size of chunks to generate after splitting. Must be greater than 0. chunk_overlap (int): The number of characters of overlap between chunks. Must be non-negative
@@ -592,36 +584,26 @@
Source code for components.data_process.text_splitter
super().__init__()self.split_by=split_by
- assert(
- split_byinSEPARATORS
- ),f"Invalid options for split_by. You must select from {list(SEPARATORS.keys())}."
-
- assert(
- chunk_overlap<chunk_size
- ),f"chunk_overlap can't be larger than or equal to chunk_size. Received chunk_size: {chunk_size}, chunk_overlap: {chunk_overlap}"
-
- assert(
- chunk_size>0
- ),f"chunk_size must be greater than 0. Received value: {chunk_size}"
+ assertsplit_byinSEPARATORS,f"Invalid options for split_by. You must select from {list(SEPARATORS.keys())}."
+
+ assertchunk_overlap<chunk_size,f"chunk_overlap can't be larger than or equal to chunk_size. Received chunk_size: {chunk_size}, chunk_overlap: {chunk_overlap}"
+
+ assertchunk_size>0,f"chunk_size must be greater than 0. Received value: {chunk_size}"self.chunk_size=chunk_size
- assert(
- chunk_overlap>=0
- ),f"chunk_overlap must be non-negative. Received value: {chunk_overlap}"
+ assertchunk_overlap>=0,f"chunk_overlap must be non-negative. Received value: {chunk_overlap}"self.chunk_overlap=chunk_overlapself.batch_size=batch_size
-
- log.info(
- f"Initialized TextSplitter with split_by={self.split_by}, chunk_size={self.chunk_size}, chunk_overlap={self.chunk_overlap}, batch_size={self.batch_size}"
- )
+
+ log.info(f"Initialized TextSplitter with split_by={self.split_by}, chunk_size={self.chunk_size}, chunk_overlap={self.chunk_overlap}, batch_size={self.batch_size}")
[docs]defsplit_text(self,text:str)->List[str]:""" Splits the provided text into chunks.
-
+ Splits based on the specified split_by, chunk size, and chunk overlap settings. Args:
@@ -630,15 +612,11 @@
Source code for components.data_process.text_splitter
Returns:
List[str]: A list of text chunks. """
- log.info(
- f"Splitting text with split_by: {self.split_by}, chunk_size: {self.chunk_size}, chunk_overlap: {self.chunk_overlap}"
- )
+ log.info(f"Splitting text with split_by: {self.split_by}, chunk_size: {self.chunk_size}, chunk_overlap: {self.chunk_overlap}")separator=SEPARATORS[self.split_by]splits=self._split_text_into_units(text,separator)log.info(f"Text split into {len(splits)} parts.")
- chunks=self._merge_units_to_chunks(
- splits,self.chunk_size,self.chunk_overlap,separator
- )
+ chunks=self._merge_units_to_chunks(splits,self.chunk_size,self.chunk_overlap,separator)log.info(f"Text merged into {len(chunks)} chunks.")returnchunks
@@ -648,13 +626,13 @@
Source code for components.data_process.text_splitter
def call(self,documents:DocumentSplitterInputType)->DocumentSplitterOutputType:""" Process the splitting task on a list of documents in batch.
-
+ Batch processes a list of documents, splitting each document's text according to the configured split_by, chunk size, and chunk overlap. Args: documents (List[Document]): A list of Document objects to process.
-
+ Returns: List[Document]: A list of new Document objects, each containing a chunk of text from the original documents.
@@ -662,29 +640,20 @@
Source code for components.data_process.text_splitter
TypeError: If 'documents' is not a list or contains non-Document objects.
ValueError: If any document's text is None. """
-
- ifnotisinstance(documents,list)orany(
- notisinstance(doc,Document)fordocindocuments
- ):
+
+ ifnotisinstance(documents,list)orany(notisinstance(doc,Document)fordocindocuments):log.error("Input should be a list of Documents.")raiseTypeError("Input should be a list of Documents.")
-
+
split_docs=[]# Using range and batch_size to create batches
- forstart_idxintqdm(
- range(0,len(documents),self.batch_size),
- desc="Splitting Documents in Batches",
- ):
- batch_docs=documents[start_idx:start_idx+self.batch_size]
-
+ forstart_idxintqdm(range(0,len(documents),self.batch_size),desc="Splitting Documents in Batches"):
+ batch_docs=documents[start_idx:start_idx+self.batch_size]
+
fordocinbatch_docs:ifnotisinstance(doc,Document):
- log.error(
- f"Each item in documents should be an instance of Document, but got {type(doc).__name__}."
- )
- raiseTypeError(
- f"Each item in documents should be an instance of Document, but got {type(doc).__name__}."
- )
+ log.error(f"Each item in documents should be an instance of Document, but got {type(doc).__name__}.")
+ raiseTypeError(f"Each item in documents should be an instance of Document, but got {type(doc).__name__}.")ifdoc.textisNone:log.error(f"Text should not be None. Doc id: {doc.id}")
@@ -693,25 +662,22 @@
Source code for components.data_process.text_splitter
-
- def_split_text_into_units(self,text:str,separator:str)->List[str]:
+
+ def_split_text_into_units(
+ self,text:str,separator:str)->List[str]:"""Split text based on the specified separator."""ifself.split_by=="token":splits=tokenizer.encode(text)
@@ -719,7 +685,7 @@
Source code for components.data_process.text_splitter
splits =text.split(separator)log.info(f"Text split by '{separator}' into {len(splits)} parts.")returnsplits
-
+
def_merge_units_to_chunks(self,splits:List[str],chunk_size:int,chunk_overlap:int,separator:str)->List[str]:
@@ -727,47 +693,45 @@
Source code for components.data_process.text_splitter
Merge split text chunks based on the specified chunk size and overlap.
"""chunks=[]
- # we use a window to get the text for each trunk, the window size is chunk_size, step is chunk_size - chunk_overlap
+ # we use a window to get the text for each trunk, the window size is chunk_size, step is chunk_size - chunk_overlap step=chunk_size-chunk_overlapidx=0
-
+
foridxinrange(0,len(splits),step):# 1. if the window exceeds the list of splitted string, break and process the last chunk# 2. if the window ends exactly the same with the splits, then break and treat the splits[idx:len(splits)] as the last chunk
- ifidx+chunk_size>=len(splits):
+ ifidx+chunk_size>=len(splits):break
- current_splits=splits[idx:idx+chunk_size]
+ current_splits=splits[idx:idx+chunk_size]# add the separator between each unit and merge the string# this won't be the last chunk, so we need to add the separator at the endifself.split_by=="token":
- chunk=current_splits# if token, then keep the original form
+ chunk=current_splits# if token, then keep the original formelse:chunk=separator.join(current_splits)+separatorchunks.append(chunk)
-
+
ifidx<len(splits):ifself.split_by=="token":last_chunk=splits[idx:]# if token, then keep the original formelse:
- last_chunk=separator.join(
- splits[idx:]
- )# if not token, then join into string
+ last_chunk=separator.join(splits[idx:])# if not token, then join into stringiflen(last_chunk)>0:chunks.append(last_chunk)
-
- ifself.split_by=="token":
+
+ ifself.split_by=="token":# decode each chunk herechunks=[tokenizer.decode(chunk)forchunkinchunks]
-
+
log.info(f"Merged into {len(chunks)} chunks.")returnchunks
-
+
def_extra_repr(self)->str:s=f"split_by={self.split_by}, chunk_size={self.chunk_size}, chunk_overlap={self.chunk_overlap}"returns
-
-
+
+
# test the execution llamaindex and langchain
-[docs]
-classAnthropicAPIClient(ModelClient):
- __doc__=r"""A component wrapper for the Anthropic API client.
-
- Visit https://docs.anthropic.com/en/docs/intro-to-claude for more api details.
- """
-
- def__init__(self,api_key:Optional[str]=None):
-r"""It is recommended to set the ANTHROPIC_API_KEY environment variable instead of passing it as an argument."""
- super().__init__()
- self._api_key=api_key
- self.sync_client=self.init_sync_client()
- self.async_client=None# only initialize if the async call is called
- self.tested_llm_models=["claude-3-opus-20240229"]
-
-
-[docs]
- definit_sync_client(self):
- api_key=self._api_keyoros.getenv("ANTHROPIC_API_KEY")
- ifnotapi_key:
- raiseValueError("Environment variable ANTHROPIC_API_KEY must be set")
- returnanthropic.Anthropic(api_key=api_key)
-
-
-
-[docs]
- definit_async_client(self):
- api_key=self._api_keyoros.getenv("ANTHROPIC_API_KEY")
- ifnotapi_key:
- raiseValueError("Environment variable ANTHROPIC_API_KEY must be set")
- returnanthropic.AsyncAnthropic(api_key=api_key)
-[docs]
-classCohereAPIClient(ModelClient):
- __doc__=r"""A component wrapper for the Cohere API.
-
- Visit https://docs.cohere.com/ for more api details.
-
- References:
- - Cohere reranker: https://docs.cohere.com/reference/rerank
-
- Tested Cohere models: 6/16/2024
- - rerank-english-v3.0, rerank-multilingual-v3.0, rerank-english-v2.0, rerank-multilingual-v2.0
- """
-
- def__init__(self,api_key:Optional[str]=None):
-r"""It is recommended to set the GROQ_API_KEY environment variable instead of passing it as an argument.
-
- Args:
- api_key (Optional[str], optional): Groq API key. Defaults to None.
- """
- super().__init__()
- self._api_key=api_key
- self.init_sync_client()
-
- self.async_client=None# only initialize if the async call is called
-
-
-[docs]
- definit_sync_client(self):
- api_key=self._api_keyoros.getenv("COHERE_API_KEY")
- ifnotapi_key:
- raiseValueError("Environment variable COHERE_API_KEY must be set")
- self.sync_client=cohere.Client(api_key=api_key)
-
-
-
-[docs]
- definit_async_client(self):
- api_key=self._api_keyoros.getenv("COHERE_API_KEY")
- ifnotapi_key:
- raiseValueError("Environment variable COHERE_API_KEY must be set")
- self.async_client=cohere.AsyncClient(api_key=api_key)
-
-
-
-[docs]
- defconvert_inputs_to_api_kwargs(
- self,
- input:Optional[Any]=None,# for retriever, it is a list of string.
- model_kwargs:Dict={},
- model_type:ModelType=ModelType.UNDEFINED,
- )->Dict:
-r"""
- For rerank model, expect model_kwargs to have the following keys:
- model: str,
- query: str,
- documents: List[str],
- top_n: int,
- """
- final_model_kwargs=model_kwargs.copy()
- ifmodel_type==ModelType.RERANKER:
- final_model_kwargs["query"]=input
- assert"model"infinal_model_kwargs,"model must be specified"
- assert"documents"infinal_model_kwargs,"documents must be specified"
- assert"top_k"infinal_model_kwargs,"top_k must be specified"
-
- # convert top_k to the api specific, which is top_n
- final_model_kwargs["top_n"]=final_model_kwargs.pop("top_k")
- returnfinal_model_kwargs
- else:
- raiseValueError(f"model_type {model_type} is not supported")
-
-
-
-[docs]
- @backoff.on_exception(
- backoff.expo,
- (
- BadRequestError,
- InternalServerError,
- ),
- max_time=5,
- )
- defcall(self,api_kwargs:Dict={},model_type:ModelType=ModelType.UNDEFINED):
- assert(
- "model"inapi_kwargs
- ),f"model must be specified in api_kwargs: {api_kwargs}"
- if(
- model_type==ModelType.RERANKER
- ):# query -> # scores for top_k documents, index for the top_k documents, return as tuple
-
- response=self.sync_client.rerank(**api_kwargs)
- top_k_scores=[result.relevance_scoreforresultinresponse.results]
- top_k_indices=[result.indexforresultinresponse.results]
- returntop_k_indices,top_k_scores
- else:
- raiseValueError(f"model_type {model_type} is not supported")
-[docs]
-classGroqAPIClient(ModelClient):
- __doc__=r"""A component wrapper for the Groq API client.
-
- Visit https://console.groq.com/docs/ for more api details.
- Check https://console.groq.com/docs/models for the available models.
-
- Tested Groq models: 4/22/2024
- - llama3-8b-8192
- - llama3-70b-8192
- - mixtral-8x7b-32768
- - gemma-7b-it
- """
-
- def__init__(self,api_key:Optional[str]=None):
-r"""It is recommended to set the GROQ_API_KEY environment variable instead of passing it as an argument.
-
- Args:
- api_key (Optional[str], optional): Groq API key. Defaults to None.
- """
- super().__init__()
- self._api_key=api_key
- self.init_sync_client()
-
- self.async_client=None# only initialize if the async call is called
-
-
-[docs]
- definit_sync_client(self):
- api_key=self._api_keyoros.getenv("GROQ_API_KEY")
- ifnotapi_key:
- raiseValueError("Environment variable GROQ_API_KEY must be set")
- self.sync_client=Groq(api_key=api_key)
-
-
-
-[docs]
- definit_async_client(self):
- api_key=self._api_keyoros.getenv("GROQ_API_KEY")
- ifnotapi_key:
- raiseValueError("Environment variable GROQ_API_KEY must be set")
- self.async_client=AsyncGroq(api_key=api_key)
-
-
-
-[docs]
- defparse_chat_completion(self,completion:Any)->str:
-"""
- Parse the completion to a string output.
- """
- returncompletion.choices[0].message.content
Source code for components.model_client.openai_client
-"""OpenAI ModelClient integration."""
-
-importos
-fromtypingimportDict,Sequence,Optional,List,Any,TypeVar,Callable
-
-importlogging
-
-fromopenaiimportOpenAI,AsyncOpenAI
-fromopenaiimport(
- APITimeoutError,
- InternalServerError,
- RateLimitError,
- UnprocessableEntityError,
- BadRequestError,
-)
-
-fromlightrag.utils.lazy_importimportsafe_import,OptionalPackages
-
-
-fromlightrag.core.model_clientimportModelClient
-fromlightrag.core.typesimportModelType,EmbedderOutput,TokenLogProb
-fromlightrag.components.model_client.utilsimportparse_embedding_response
-
-
-safe_import(OptionalPackages.OPENAI.value[0],OptionalPackages.OPENAI.value[1])
-
-
-fromopenai.typesimportCompletion,CreateEmbeddingResponse
-
-
-importbackoff
-
-log=logging.getLogger(__name__)
-T=TypeVar("T")
-
-
-# completion parsing functions and you can combine them into one singple chat completion parser
-
-[docs]
-defget_first_message_content(completion:Completion)->str:
-r"""When we only need the content of the first message.
- It is the default parser for chat completion."""
- returncompletion.choices[0].message.content
-
-
-
-
-[docs]
-defget_all_messages_content(completion:Completion)->List[str]:
-r"""When the n > 1, get all the messages content."""
- return[c.message.contentforcincompletion.choices]
-
-
-
-
-[docs]
-defget_probabilities(completion:Completion)->List[List[TokenLogProb]]:
-r"""Get the probabilities of each token in the completion."""
- log_probs=[]
- forcincompletion.choices:
- content=c.logprobs.content
- print(content)
- log_probs_for_choice=[]
- foropenai_token_logprobincontent:
- token=openai_token_logprob.token
- logprob=openai_token_logprob.logprob
- log_probs_for_choice.append(TokenLogProb(token=token,logprob=logprob))
- log_probs.append(log_probs_for_choice)
- returnlog_probs
-
-
-
-
-[docs]
-classOpenAIClient(ModelClient):
- __doc__=r"""A component wrapper for the OpenAI API client.
-
- Support both embedding and chat completion API.
-
- Users (1) simplify use ``Embedder`` and ``Generator`` components by passing OpenAIClient() as the model_client.
- (2) can use this as an example to create their own API client or extend this class(copying and modifing the code) in their own project.
-
- Note:
- We suggest users not to use `response_format` to enforce output data type or `tools` and `tool_choice` in your model_kwargs when calling the API.
- We do not know how OpenAI is doing the formating or what prompt they have added.
- Instead
- - use :ref:`OutputParser<components-output_parsers>` for response parsing and formating.
-
- Args:
- api_key (Optional[str], optional): OpenAI API key. Defaults to None.
- chat_completion_parser (Callable[[Completion], Any], optional): A function to parse the chat completion to a str. Defaults to None.
- Default is `get_first_message_content`.
-
- References:
- - Embeddings models: https://platform.openai.com/docs/guides/embeddings
- - Chat models: https://platform.openai.com/docs/guides/text-generation
- - OpenAI docs: https://platform.openai.com/docs/introduction
- """
-
- def__init__(
- self,
- api_key:Optional[str]=None,
- chat_completion_parser:Callable[[Completion],Any]=None,
- ):
-r"""It is recommended to set the OPENAI_API_KEY environment variable instead of passing it as an argument.
-
- Args:
- api_key (Optional[str], optional): OpenAI API key. Defaults to None.
- """
- super().__init__()
- self._api_key=api_key
- self.sync_client=self.init_sync_client()
- self.async_client=None# only initialize if the async call is called
- self.chat_completion_parser=(
- chat_completion_parserorget_first_message_content
- )
-
-
-[docs]
- definit_sync_client(self):
- api_key=self._api_keyoros.getenv("OPENAI_API_KEY")
- ifnotapi_key:
- raiseValueError("Environment variable OPENAI_API_KEY must be set")
- returnOpenAI(api_key=api_key)
-
-
-
-[docs]
- definit_async_client(self):
- api_key=self._api_keyoros.getenv("OPENAI_API_KEY")
- ifnotapi_key:
- raiseValueError("Environment variable OPENAI_API_KEY must be set")
- returnAsyncOpenAI(api_key=api_key)
-
-
-
-[docs]
- defparse_chat_completion(self,completion:Completion)->Any:
-"""Parse the completion to a str."""
- log.debug(f"completion: {completion}")
- returnself.chat_completion_parser(completion)
-[docs]
- defparse_embedding_response(
- self,response:CreateEmbeddingResponse
- )->EmbedderOutput:
-r"""Parse the embedding response to a structure LightRAG components can understand.
-
- Should be called in ``Embedder``.
- """
- try:
- returnparse_embedding_response(response)
- exceptExceptionase:
- log.error(f"Error parsing the embedding response: {e}")
- returnEmbedderOutput(data=[],error=str(e),raw_response=response)
-
-
-
-[docs]
- defconvert_inputs_to_api_kwargs(
- self,
- input:Optional[Any]=None,
- model_kwargs:Dict={},
- model_type:ModelType=ModelType.UNDEFINED,
- )->Dict:
-r"""
- Specify the API input type and output api_kwargs that will be used in _call and _acall methods.
- Convert the Component's standard input, and system_input(chat model) and model_kwargs into API-specific format
- """
- final_model_kwargs=model_kwargs.copy()
- ifmodel_type==ModelType.EMBEDDER:
- ifisinstance(input,str):
- input=[input]
- # convert input to input
- assertisinstance(input,Sequence),"input must be a sequence of text"
- final_model_kwargs["input"]=input
- elifmodel_type==ModelType.LLM:
- # convert input to messages
- messages:List[Dict[str,str]]=[]
- ifinputisnotNoneandinput!="":
- messages.append({"role":"system","content":input})
- assertisinstance(
- messages,Sequence
- ),"input must be a sequence of messages"
- final_model_kwargs["messages"]=messages
- else:
- raiseValueError(f"model_type {model_type} is not supported")
- returnfinal_model_kwargs
-[docs]
- defto_dict(self)->Dict[str,Any]:
-r"""Convert the component to a dictionary."""
- # TODO: not exclude but save yes or no for recreating the clients
- exclude=[
- "sync_client",
- "async_client",
- ]# unserializable object
- output=super().to_dict(exclude=exclude)
- returnoutput
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/_modules/components/model_client/transformers_client.html b/_modules/components/model_client/transformers_client.html
index 04abf4967..aebd472b8 100644
--- a/_modules/components/model_client/transformers_client.html
+++ b/_modules/components/model_client/transformers_client.html
@@ -29,7 +29,7 @@
-
+
@@ -422,7 +422,7 @@
Source code for components.model_client.transformers_client
Source code for components.model_client.transformers_client
self.model=AutoModelForCausalLM.from_pretrained(model_name)# register the modelself.models[model_name]=self.model
- self.device="cuda"iftorch.cuda.is_available()else"cpu"
+ self.device='cuda'iftorch.cuda.is_available()else'cpu'log.info(f"Done loading model {model_name}")# Set pad token if it's not already setifself.tokenizer.pad_tokenisNone:self.tokenizer.pad_token=self.tokenizer.eos_token# common fallback
- self.model.config.pad_token_id=(
- self.tokenizer.eos_token_id
- )# ensure consistency in the model config
+ self.model.config.pad_token_id=self.tokenizer.eos_token_id# ensure consistency in the model configexceptExceptionase:log.error(f"Error loading model {model_name}: {e}")raisee
-
+
[docs]defparse_chat_completion(self,input_text:str,response:str):
- parsed_response=response.replace(
- input_text,""
- ).strip()# Safely handle cases where input_text might not be in response
-
+ parsed_response=response.replace(input_text,"").strip()# Safely handle cases where input_text might not be in response
+
returnparsed_responseifparsed_responseelseresponse
-
+
[docs]
- defcall(
- self,
- input_text:str,
- skip_special_tokens:bool=True,
- clean_up_tokenization_spaces:bool=False,
- max_length:int=150,
- ):
+ defcall(self,input_text:str,skip_special_tokens:bool=True,clean_up_tokenization_spaces:bool=False,max_length:int=150):ifnotself.model:log.error("Model is not initialized.")raiseValueError("Model is not initialized.")
-
+
# Ensure tokenizer has pad token; set it if notifself.tokenizer.pad_tokenisNone:self.tokenizer.pad_token=self.tokenizer.eos_token
- self.model.config.pad_token_id=(
- self.tokenizer.eos_token_id
- )# Sync model config pad token id
+ self.model.config.pad_token_id=self.tokenizer.eos_token_id# Sync model config pad token id# Process inputs with attention mask and padding
- inputs=self.tokenizer(input_text,return_tensors="pt",padding=True).to(
- self.device
- )
+ inputs=self.tokenizer(input_text,return_tensors="pt",padding=True).to(self.device)# inputs = self.tokenizer(input_text, return_tensors="pt", padding="longest", truncation=True).to(self.device)withtorch.no_grad():# Ensures no gradients are calculated to save memory and computationsgenerate_ids=self.model.generate(
- inputs["input_ids"],
- attention_mask=inputs["attention_mask"],
- max_length=max_length,# Control the output length more precisely
- )
- response=self.tokenizer.decode(
- generate_ids[0],
- skip_special_tokens=skip_special_tokens,
- clean_up_tokenization_spaces=clean_up_tokenization_spaces,
+ inputs['input_ids'],
+ attention_mask=inputs['attention_mask'],
+ max_length=max_length# Control the output length more precisely)
+ response=self.tokenizer.decode(generate_ids[0],skip_special_tokens=skip_special_tokens,clean_up_tokenization_spaces=clean_up_tokenization_spaces)parsed_response=self.parse_chat_completion(input_text,response)returnparsed_response
Source code for components.reasoning.chain_of_thought
+"""
+https://arxiv.org/abs/2201.11903, published in Jan, 2023
+
+Chain of the thought(CoT) is to mimic a step-by-step thought process for arriving at the answer. You can achieve it in two ways:
+1. Add instructions such as "Let's think step-by-step to answer this question".
+2. Add few-shot examples such as
+'
+Q: Roger has 5 tennis balls. He buys 2 more cans of tennis balls. Each can has 3 tennis balls. How many tennis balls does he have now?
+A: Roger started with 5 balls. 2 cansof 3 tennis balls each is 6 tennis balls. 5 + 6 = 11. The answer is 11.
+'
+
+NOTE: CoT can be helpful for more complicated task, it also varies from task to task and model to model.
+For instance, CoT might already be supported in gpt3.5+ api calls.
+
+Benchmark it with and without CoT to see if it helps.
+"""
+
+fromtypingimportDict,Optional
+
+fromcore.componentimportComponent
+fromcore.generatorimportGenerator
+fromcore.string_parserimportJsonParser
+fromcore.model_clientimportModelClient
+fromcore.default_prompt_templateimportDEFAULT_LIGHTRAG_SYSTEM_PROMPT
+
+
+COT_TASK_DESC_STR_BASIC=(
+ "You are a helpful assistant. Let's think step-by-step to answer user's query."
+)
+# Using triple quotes to include JSON-like structure more cleanly
+COT_TASK_DESC_STR_WITH_JSON_OUTPUT=f"""
+{COT_TASK_DESC_STR_BASIC} Output JSON format: {{"thought": "<The thought process to answer the query>", "answer": "<The answer to the query>"}}
+"""
+
+
+# ChainOfThought will just be a generator with preset_prompt_kwargs of the task_desc_str = COT_TASK_DESC_STR
+# additional you can ask it to generate a json with "thought" and "anwer" keys and use jsonParser
+
+
+
+[docs]
+classCoTGenerator(Generator):
+r"""
+ CoTGenerator is a subclass of Generator with default task_desc_str preset for Chain of Thought.
+ Output will be string.
+ It is exactly the same as using a Generator.
+ Example:
+ ```
+ cot = CoTGenerator(model_client=model_client, model_kwargs={"model": model})
+ ```
+ """
+
+ def__init__(
+ self,
+ *,
+ model_client:ModelClient,
+ model_kwargs:Dict={},
+ template:Optional[str]=None,
+ preset_prompt_kwargs:Optional[Dict]=None,
+ output_processors:Optional[Component]=None,
+ )->None:
+
+ super().__init__(
+ model_client=model_client,
+ model_kwargs=model_kwargs,
+ template=templateorDEFAULT_LIGHTRAG_SYSTEM_PROMPT,
+ preset_prompt_kwargs=preset_prompt_kwargs
+ or{"task_desc_str":COT_TASK_DESC_STR_BASIC},
+ output_processors=output_processors,
+ )
+
+
+
+
+[docs]
+classCoTGeneratorWithJsonOutput(Generator):
+r"""
+ CoTGeneratorWithJsonOutput is a subclass of Generator with default task_desc_str preset for Chain of Thought.
+ Output will be parsed as JSON with "thought" and "answer" keys.
+ Example:
+ ```
+ cot = CoTGeneratorWithJsonOutput(model_client=model_client, model_kwargs={"model": model})
+ ```
+ """
+
+ def__init__(
+ self,
+ *,
+ model_client:ModelClient,
+ model_kwargs:Dict={},
+ template:Optional[str]=None,
+ preset_prompt_kwargs:Optional[Dict]=None,
+ output_processors:Optional[Component]=None,
+ )->None:
+
+ super().__init__(
+ model_client=model_client,
+ model_kwargs=model_kwargs,
+ template=templateorDEFAULT_LIGHTRAG_SYSTEM_PROMPT,
+ preset_prompt_kwargs=preset_prompt_kwargs
+ or{"task_desc_str":COT_TASK_DESC_STR_WITH_JSON_OUTPUT},
+ output_processors=output_processorsorJsonParser(),
+ )