MCPcopy Create free account
hub / github.com/cocoindex-io/cocoindex-code / _resolve_embedding_choice

Function _resolve_embedding_choice

src/cocoindex_code/cli.py:343–415  ·  view source on GitHub ↗

Resolve the embedding settings per the init control-flow diagram. On a retry, ``previous`` holds the choice from the last attempt; its provider and model become the prompt defaults so the user only edits what was wrong instead of retyping everything.

(
    litellm_model_flag: str | None,
    st_installed: bool,
    tty: bool,
    previous: EmbeddingSettings | None = None,
)

Source from the content-addressed store, hash-verified

341
342
343def _resolve_embedding_choice(
344 litellm_model_flag: str | None,
345 st_installed: bool,
346 tty: bool,
347 previous: EmbeddingSettings | None = None,
348) -> EmbeddingSettings:
349 """Resolve the embedding settings per the init control-flow diagram.
350
351 On a retry, ``previous`` holds the choice from the last attempt; its
352 provider and model become the prompt defaults so the user only edits
353 what was wrong instead of retyping everything.
354 """
355 if litellm_model_flag is not None:
356 return EmbeddingSettings(provider="litellm", model=litellm_model_flag)
357
358 if not tty:
359 if st_installed:
360 return EmbeddingSettings(provider="sentence-transformers", model=DEFAULT_ST_MODEL)
361 _typer.echo(
362 "Error: sentence-transformers is not installed and stdin is not a TTY.\n"
363 "Either install the extra (`pip install 'cocoindex-code[embeddings-local]'`)\n"
364 "or pass `--litellm-model MODEL` to select a LiteLLM model.",
365 err=True,
366 )
367 raise _typer.Exit(code=1)
368
369 # Interactive
370 import questionary
371
372 if st_installed:
373 provider = questionary.select(
374 "Embedding provider",
375 choices=[
376 questionary.Choice(
377 title="sentence-transformers (local, free — built-in HuggingFace models)",
378 value="sentence-transformers",
379 ),
380 questionary.Choice(
381 title="litellm (100+ providers — cloud APIs & local Ollama)",
382 value="litellm",
383 ),
384 ],
385 default=previous.provider if previous is not None else None,
386 ).ask()
387 else:
388 _typer.echo(
389 "sentence-transformers is not installed — only `litellm` is available.\n"
390 "To enable local embeddings, install `cocoindex-code[embeddings-local]`."
391 )
392 provider = "litellm"
393
394 if provider is None: # user cancelled (Ctrl-C / Esc)
395 raise _typer.Exit(code=1)
396
397 if provider == "sentence-transformers":
398 default_model = previous.model if previous is not None else DEFAULT_ST_MODEL
399 model = questionary.text(
400 "Model name",

Calls 3

EmbeddingSettingsClass · 0.85
askMethod · 0.80