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

update(kag) update kag_config.yaml for examples #177

Merged
merged 10 commits into from
Dec 28, 2024
18 changes: 16 additions & 2 deletions kag/bin/commands/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,28 @@ def handle_cls(args: argparse.Namespace):
availables = cls_obj.list_available_with_detail()
seg = " " * 20

deduped_availables = {}
for register_name, cls_info in availables.items():
cls = cls_info["class"]
if cls not in deduped_availables:
deduped_availables[cls] = [register_name]
else:
deduped_availables[cls].append(register_name)

print(f"{bold}{red}{seg}Documentation of {args.cls}{seg}{reset}")
import inspect

print(inspect.getdoc(cls_obj))
print(f"{bold}{red}{seg}Registered subclasses of {args.cls}{seg}{reset}")
visited = set()
for register_name, cls_info in availables.items():
print(f"{bold}{blue}[{cls_info['class']}]{reset}")
print(f"{bold}{green}Register Name:{reset} {register_name}\n")
cls = cls_info["class"]
if cls in visited:
continue
visited.add(cls)
print(f"{bold}{blue}[{cls}]{reset}")
register_names = " / ".join([f'"{x}"' for x in deduped_availables[cls]])
print(f"{bold}{green}Register Name:{reset} {register_names}\n")

# print(f"Class Name: {cls_info['class']}")
print(f"{bold}{green}Documentation:{reset}\n{cls_info['doc']}\n")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@


@ExtractorABC.register("schema_constraint")
@ExtractorABC.register("schema_constraint_extractor")
class SchemaConstraintExtractor(ExtractorABC):
"""
Perform knowledge extraction for enforcing schema constraints, including entities, events and their edges.
Expand Down
1 change: 1 addition & 0 deletions kag/builder/component/extractor/schema_free_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@


@ExtractorABC.register("schema_free")
@ExtractorABC.register("schema_free_extractor")
class SchemaFreeExtractor(ExtractorABC):
"""
A class for extracting knowledge graph subgraphs from text using a large language model (LLM).
Expand Down
1 change: 1 addition & 0 deletions kag/builder/component/mapping/spg_type_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@


@MappingABC.register("spg")
@MappingABC.register("spg_mapping")
class SPGTypeMapping(MappingABC):
"""
A class for mapping SPG(Semantic-enhanced Programmable Graph) types and handling their properties and strategies.
Expand Down
1 change: 1 addition & 0 deletions kag/builder/component/mapping/spo_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@


@MappingABC.register("spo")
@MappingABC.register("spo_mapping")
class SPOMapping(MappingABC):
"""
A class that extends the MappingABC base class.
Expand Down
1 change: 1 addition & 0 deletions kag/builder/component/postprocessor/kag_postprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@


@PostProcessorABC.register("base", as_default=True)
@PostProcessorABC.register("kag_post_processor", as_default=True)
class KAGPostProcessor(PostProcessorABC):
"""
A class that extends the PostProcessorABC base class.
Expand Down
1 change: 1 addition & 0 deletions kag/builder/component/reader/dict_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@


@ReaderABC.register("dict")
@ReaderABC.register("dict_reader")
class DictReader(ReaderABC):
"""
A class for reading dictionaries into Chunk objects.
Expand Down
1 change: 1 addition & 0 deletions kag/builder/component/reader/txt_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@


@ReaderABC.register("txt")
@ReaderABC.register("txt_reader")
class TXTReader(ReaderABC):
"""
A class for parsing text files or text content into Chunk objects.
Expand Down
1 change: 1 addition & 0 deletions kag/builder/component/scanner/csv_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@


@ScannerABC.register("csv")
@ScannerABC.register("csv_scanner")
class CSVScanner(ScannerABC):
def __init__(
self,
Expand Down
3 changes: 3 additions & 0 deletions kag/builder/component/scanner/dataset_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@


@ScannerABC.register("hotpotqa")
@ScannerABC.register("hotpotqa_dataset_scanner")
class HotpotqaCorpusScanner(ScannerABC):
"""
A class for reading HotpotQA dataset and converting it into a list of dictionaries, inheriting from `ScannerABC`.
Expand Down Expand Up @@ -66,6 +67,8 @@ def load_data(self, input: Input, **kwargs) -> List[Output]:

@ScannerABC.register("musique")
@ScannerABC.register("2wiki")
@ScannerABC.register("musique_dataset_scanner")
@ScannerABC.register("2wiki_dataset_scanner")
class MusiqueCorpusScanner(ScannerABC):
"""
A class for reading Musique/2Wiki dataset and converting it into a list of dictionaries, inheriting from `ScannerABC`.
Expand Down
1 change: 1 addition & 0 deletions kag/builder/component/scanner/directory_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@


@ScannerABC.register("dir")
@ScannerABC.register("dir_file_scanner")
class DirectoryScanner(ScannerABC):
"""
A class for reading files from a directory based on a specified file pattern or suffix, inheriting from `ScannerABC`.
Expand Down
1 change: 1 addition & 0 deletions kag/builder/component/splitter/length_splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@


@SplitterABC.register("length")
@SplitterABC.register("length_splitter")
class LengthSplitter(BaseTableSplitter):
"""
A class for splitting text based on length.
Expand Down
1 change: 1 addition & 0 deletions kag/builder/component/vectorizer/batch_vectorizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def batch_generate(self, node_batch, batch_size=32):


@VectorizerABC.register("batch")
@VectorizerABC.register("batch_vectorizer")
class BatchVectorizer(VectorizerABC):
"""
A class for generating embedding vectors for node attributes in a SubGraph in batches.
Expand Down
1 change: 1 addition & 0 deletions kag/builder/component/writer/kg_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class AlterOperationEnum(str, Enum):


@SinkWriterABC.register("kg", as_default=True)
@SinkWriterABC.register("kg_writer", as_default=True)
class KGWriter(SinkWriterABC):
"""
A class for writing SubGraphs to a Knowledge Graph (KG) storage.
Expand Down
4 changes: 3 additions & 1 deletion kag/builder/default_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@


@KAGBuilderChain.register("structured")
@KAGBuilderChain.register("structured_builder_chain")
class DefaultStructuredBuilderChain(KAGBuilderChain):
"""
A class representing a default SPG builder chain, used to import structured data based on schema definitions.
Expand Down Expand Up @@ -84,6 +85,7 @@ def build(self, **kwargs):


@KAGBuilderChain.register("unstructured")
@KAGBuilderChain.register("unstructured_builder_chain")
class DefaultUnstructuredBuilderChain(KAGBuilderChain):
"""
A class representing a default unstructured builder chain, used to build a knowledge graph from unstructured text data such as txt and pdf files.
Expand Down Expand Up @@ -169,7 +171,7 @@ def run_extract(chunk):
for inner_future in tqdm(
as_completed(futures),
total=len(futures),
desc="Chunk Extraction",
desc="KAG Extraction From Chunk",
position=1,
leave=False,
):
Expand Down
2 changes: 1 addition & 1 deletion kag/examples/2wiki/builder/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
def buildKB(file_path):
from kag.common.conf import KAG_CONFIG

runner = BuilderChainRunner.from_config(KAG_CONFIG.all_config["runner"])
runner = BuilderChainRunner.from_config(KAG_CONFIG.all_config["kag_builder_pipeline"])
runner.invoke(file_path)

logger.info(f"\n\nbuildKB successfully for {file_path}\n\n")
Expand Down
70 changes: 0 additions & 70 deletions kag/examples/2wiki/kag_config-tc.yaml

This file was deleted.

Loading
Loading