MCPcopy
hub / github.com/PromtEngineer/localGPT / IndexCreator

Class IndexCreator

create_index_script.py:36–311  ·  view source on GitHub ↗

Interactive index creation utility.

Source from the content-addressed store, hash-verified

34
35
36class IndexCreator:
37 """Interactive index creation utility."""
38
39 def __init__(self, config_path: Optional[str] = None):
40 """Initialize the index creator with optional custom configuration."""
41 self.db = ChatDatabase()
42 self.config = self._load_config(config_path)
43
44 # Initialize Ollama client
45 self.ollama_client = OllamaClient()
46 self.ollama_config = {
47 "generation_model": "qwen3:0.6b",
48 "embedding_model": "qwen3:0.6b"
49 }
50
51 # Initialize indexing pipeline
52 self.pipeline = IndexingPipeline(
53 self.config,
54 self.ollama_client,
55 self.ollama_config
56 )
57
58 def _load_config(self, config_path: Optional[str] = None) -> dict:
59 """Load configuration from file or use default."""
60 if config_path and os.path.exists(config_path):
61 try:
62 with open(config_path, 'r') as f:
63 return json.load(f)
64 except Exception as e:
65 print(f"⚠️ Error loading config from {config_path}: {e}")
66 print("Using default configuration...")
67
68 return PIPELINE_CONFIGS.get("default", {})
69
70 def get_user_input(self, prompt: str, default: str = "") -> str:
71 """Get user input with optional default value."""
72 if default:
73 user_input = input(f"{prompt} [{default}]: ").strip()
74 return user_input if user_input else default
75 return input(f"{prompt}: ").strip()
76
77 def select_documents(self) -> List[str]:
78 """Interactive document selection."""
79 print("\n📁 Document Selection")
80 print("=" * 50)
81
82 documents = []
83
84 while True:
85 print("\nOptions:")
86 print("1. Add a single document")
87 print("2. Add all documents from a directory")
88 print("3. Finish and proceed with selected documents")
89 print("4. Show selected documents")
90
91 choice = self.get_user_input("Select an option (1-4)", "1")
92
93 if choice == "1":

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected