embed the query text :param query: the query text :param embedding_model: the embedding_model to use :param embedding_size: the embedding size of the model :return: the embedding vector
(query: str, embedding_model: Model, embedding_size: int)
| 28 | |
| 29 | |
| 30 | async def embed_query(query: str, embedding_model: Model, embedding_size: int): |
| 31 | """ |
| 32 | embed the query text |
| 33 | :param query: the query text |
| 34 | :param embedding_model: the embedding_model to use |
| 35 | :param embedding_size: the embedding size of the model |
| 36 | :return: the embedding vector |
| 37 | """ |
| 38 | |
| 39 | if CONFIG.DEV: |
| 40 | return _generate_random_unit_vector(query, embedding_size) |
| 41 | |
| 42 | response = await text_embedding( |
| 43 | model=embedding_model, |
| 44 | encrypted_credentials=embedding_model.encrypted_credentials, |
| 45 | input_text_list=[query], |
| 46 | input_type="query", |
| 47 | ) |
| 48 | check_http_error(response) |
| 49 | return response.json()["data"][0]["embedding"] |
| 50 | |
| 51 | |
| 52 | async def embed_documents(documents: List[str], embedding_model: Model, embedding_size: int) -> List[List[float]]: |
no test coverage detected