Update a single section (vlm / embedding / server) of an existing ov.conf.
(config_path: Path, section: str)
| 1837 | |
| 1838 | |
| 1839 | def _update_existing_config(config_path: Path, section: str) -> int: |
| 1840 | """Update a single section (vlm / embedding / server) of an existing ov.conf.""" |
| 1841 | try: |
| 1842 | data = json.loads(config_path.read_text(encoding="utf-8-sig")) |
| 1843 | except (OSError, json.JSONDecodeError, UnicodeDecodeError) as exc: |
| 1844 | print(f" {_red(f'Cannot read existing config: {exc}')}") |
| 1845 | print(f" {_dim('Fix or remove the file, then re-run `openviking-server init`.')}") |
| 1846 | return 1 |
| 1847 | if not isinstance(data, dict): |
| 1848 | print(f" {_red('Existing config is not a JSON object; cannot update in place.')}") |
| 1849 | return 1 |
| 1850 | |
| 1851 | if section == "vlm": |
| 1852 | current_vlm = _config_section(data, "vlm") |
| 1853 | print(f"\n Current VLM: {_summarize_model(current_vlm)}") |
| 1854 | vlm_config, _ = _prompt_cloud_vlm(current=current_vlm) |
| 1855 | if vlm_config is None: |
| 1856 | print("\n Setup cancelled.\n") |
| 1857 | return 0 |
| 1858 | old_summary, new_summary = _summarize_model(current_vlm), _summarize_model(vlm_config) |
| 1859 | data["vlm"] = vlm_config |
| 1860 | elif section == "embedding": |
| 1861 | old_dense = _config_section(data, "embedding", "dense") |
| 1862 | old_dim = old_dense.get("dimension") |
| 1863 | print(f"\n Current embedding: {_summarize_model(old_dense)}") |
| 1864 | dense, _ = _prompt_embedding_flow(current=old_dense) |
| 1865 | if dense is _CUSTOM_SETUP: |
| 1866 | return 0 |
| 1867 | if dense is None: |
| 1868 | print("\n Setup cancelled.\n") |
| 1869 | return 0 |
| 1870 | if old_dim and dense.get("dimension") != old_dim: |
| 1871 | print( |
| 1872 | f"\n {_yellow('Embedding dimension changes from ' + str(old_dim) + ' to ' + str(dense.get('dimension')) + '.')}" |
| 1873 | ) |
| 1874 | print( |
| 1875 | f" {_yellow('Existing vector indexes become unusable — data must be re-ingested.')}" |
| 1876 | ) |
| 1877 | if not _prompt_confirm("Continue?", default=False): |
| 1878 | print("\n Setup cancelled.\n") |
| 1879 | return 0 |
| 1880 | old_summary, new_summary = _summarize_model(old_dense), _summarize_model(dense) |
| 1881 | data.setdefault("embedding", {})["dense"] = dense |
| 1882 | else: # server |
| 1883 | current_server = _config_section(data, "server") |
| 1884 | server_dict = _wizard_server(current=current_server) |
| 1885 | if server_dict is None: |
| 1886 | print("\n Setup cancelled.\n") |
| 1887 | return 0 |
| 1888 | old_summary, new_summary = ( |
| 1889 | _summarize_server(current_server), |
| 1890 | _summarize_server(server_dict), |
| 1891 | ) |
| 1892 | data["server"] = server_dict |
| 1893 | |
| 1894 | print(f"\n {_bold('Change:')} {old_summary}") |
| 1895 | print(f" {_cyan('→')} {new_summary}") |
| 1896 |