# semantic_search

> **Function** in `langchain_google_vertexai`

📖 [View in docs](https://reference.langchain.com/python/langchain-google-vertexai/vectorstores/_v2_operations/semantic_search)

Performs semantic search in a Vertex AI Vector Search 2.0 Collection.

Semantic search automatically generates embeddings from the search text
using Vertex AI models, so you don't need to manually create embeddings.

## Signature

```python
semantic_search(
    project_id: str,
    region: str,
    collection_id: str,
    search_text: str,
    search_field: str,
    num_neighbors: int,
    task_type: str = 'RETRIEVAL_QUERY',
    filter_: dict | None = None,
    credentials: Optional[Credentials] = None,
) -> List[dict[str, Any]]
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `project_id` | `str` | Yes | The GCP project ID. |
| `region` | `str` | Yes | The GCP region. |
| `collection_id` | `str` | Yes | The collection ID. |
| `search_text` | `str` | Yes | Natural language query text. |
| `search_field` | `str` | Yes | Name of the vector field to search (must have auto-embedding config). |
| `num_neighbors` | `int` | Yes | Number of neighbors to return. |
| `task_type` | `str` | No | Embedding task type. Options: - "RETRIEVAL_QUERY": For search queries (default) - "RETRIEVAL_DOCUMENT": For document indexing - "SEMANTIC_SIMILARITY": For semantic similarity - "CLASSIFICATION": For classification tasks - "CLUSTERING": For clustering tasks (default: `'RETRIEVAL_QUERY'`) |
| `filter_` | `dict \| None` | No | Optional filter dict. Examples: {"genre": {"$eq": "Drama"}},          {"$and": [{"year": {"$gte": 1990}}, {"genre": {"$eq": "Action"}}]} (default: `None`) |
| `credentials` | `Optional[Credentials]` | No | Optional credentials to use. (default: `None`) |

## Returns

`List[dict[str, Any]]`

List of search results with doc_id, score, and metadata.

---

[View source on GitHub](https://github.com/langchain-ai/langchain-google/blob/a3f016b2a6c4af535df275545f76fa7424aa39e5/libs/vertexai/langchain_google_vertexai/vectorstores/_v2_operations.py#L335)