def embed()

in src/databao_context_engine/llm/service.py [0:0]


    def embed(self, *, model: str, text: str) -> list[float]:
        payload: dict[str, Any] = {
            "model": model,
            "prompt": text,
        }
        data = self._request_json(method="POST", path="/api/embeddings", json=payload)

        vec = data.get("embedding")
        if not isinstance(vec, list) or not all(isinstance(x, (int, float)) for x in vec):
            alt = data.get("data")
            if isinstance(alt, list) and alt and isinstance(alt[0], dict) and isinstance(alt[0].get("embedding"), list):
                vec = alt[0]["embedding"]
            else:
                raise ValueError("Unexpected Ollama embedding response schema")

        return [float(x) for x in vec]