diff --git a/content/develop/ai/redisvl/api/query.md b/content/develop/ai/redisvl/api/query.md index 03e064b3c5..78204d6c3c 100644 --- a/content/develop/ai/redisvl/api/query.md +++ b/content/develop/ai/redisvl/api/query.md @@ -12,7 +12,7 @@ queries for different use cases. Each query class wraps the `redis-py` Query mod ## VectorQuery -### `class VectorQuery(vector, vector_field_name, return_fields=None, filter_expression=None, dtype='float32', num_results=10, return_score=True, dialect=2, sort_by=None, in_order=False, hybrid_policy=None, batch_size=None, ef_runtime=None, epsilon=None, search_window_size=None, use_search_history=None, search_buffer_capacity=None, normalize_vector_distance=False)` +### `class VectorQuery(vector, vector_field_name, return_fields=None, filter_expression=None, dtype='float32', num_results=10, return_score=True, dialect=2, sort_by=None, in_order=False, hybrid_policy=None, batch_size=None, ef_runtime=None, search_window_size=None, use_search_history=None, search_buffer_capacity=None, normalize_vector_distance=False)` Bases: `BaseVectorQuery`, `BaseQuery` @@ -57,10 +57,6 @@ expression. * **ef_runtime** (*Optional* *[* *int* *]*) – Controls the size of the dynamic candidate list for HNSW algorithm at query time. Higher values improve recall at the expense of slower search performance. Defaults to None, which uses the index-defined value. - * **epsilon** (*Optional* *[* *float* *]*) – The range search approximation factor for HNSW and SVS-VAMANA - indexes. Sets boundaries for candidates within radius \* (1 + epsilon). Higher values - allow more extensive search and more accurate results at the expense of run time. - Defaults to None, which uses the index-defined value (typically 0.01). * **search_window_size** (*Optional* *[* *int* *]*) – The size of the search window for SVS-VAMANA KNN searches. Increasing this value generally yields more accurate but slower search results. Defaults to None, which uses the index-defined value (typically 10). @@ -231,19 +227,6 @@ Set the EF_RUNTIME parameter for the query. * **TypeError** – If ef_runtime is not an integer * **ValueError** – If ef_runtime is not positive -#### `set_epsilon(epsilon)` - -Set the epsilon parameter for the query. - -* **Parameters:** - **epsilon** (*float*) – The range search approximation factor for HNSW and SVS-VAMANA - indexes. Sets boundaries for candidates within radius \* (1 + epsilon). - Higher values allow more extensive search and more accurate results at the - expense of run time. -* **Raises:** - * **TypeError** – If epsilon is not a float or int - * **ValueError** – If epsilon is negative - #### `set_filter(filter_expression=None)` Set the filter expression for the query. @@ -394,15 +377,6 @@ Return the EF_RUNTIME parameter for the query. * **Return type:** Optional[int] -#### `property epsilon: float | None` - -Return the epsilon parameter for the query. - -* **Returns:** - The epsilon value for the query. -* **Return type:** - Optional[float] - #### `property filter: str | `[`FilterExpression`]({{< relref "filter/#filterexpression" >}})` ` The filter expression for the query. diff --git a/content/develop/ai/redisvl/user_guide/how_to_guides/vectorizers.md b/content/develop/ai/redisvl/user_guide/how_to_guides/vectorizers.md index 04e99f758f..50212a9c80 100644 --- a/content/develop/ai/redisvl/user_guide/how_to_guides/vectorizers.md +++ b/content/develop/ai/redisvl/user_guide/how_to_guides/vectorizers.md @@ -7,19 +7,19 @@ weight: 04 --- -This guide demonstrates how to create embeddings using RedisVL's built-in text vectorizers. RedisVL supports multiple embedding providers: OpenAI, HuggingFace, Vertex AI, Cohere, Mistral AI, Amazon Bedrock, VoyageAI, and custom vectorizers. +This guide demonstrates how to create embeddings using RedisVL's built-in text vectorizers. RedisVL supports multiple embedding providers: OpenAI, HuggingFace, Ollama, Vertex AI, Cohere, Mistral AI, Amazon Bedrock, VoyageAI, and custom vectorizers. ## Prerequisites Before you begin, ensure you have: - Installed RedisVL: `pip install redisvl` - A running Redis instance ([Redis 8+](https://redis.io/downloads/) or [Redis Cloud](https://redis.io/cloud)) -- API keys for the embedding providers you plan to use +- API keys or local model servers for the embedding providers you plan to use ## What You'll Learn By the end of this guide, you will be able to: -- Create embeddings using multiple providers (OpenAI, HuggingFace, Cohere, etc.) +- Create embeddings using multiple providers (OpenAI, HuggingFace, Ollama, Cohere, etc.) - Use synchronous and asynchronous embedding methods - Batch embed multiple texts efficiently - Build custom vectorizers for your own embedding functions @@ -220,6 +220,58 @@ embeddings = hf.embed_many(sentences, as_buffer=True) ``` +### Ollama + +[Ollama](https://ollama.com/) lets you run embedding models locally. RedisVL supports Ollama through the `OllamaTextVectorizer`. + +Install the Python client and pull an embedding model before running this example: + +```bash +pip install 'redisvl[ollama]' +ollama pull nomic-embed-text +``` + +Make sure the Ollama daemon is running with `ollama serve`. By default, the Ollama client uses `OLLAMA_HOST` if set, otherwise it connects to `http://localhost:11434`. To connect to a custom Ollama server explicitly, pass `host="http://your-host:11434"` when creating the vectorizer. + + +```python +from redisvl.utils.vectorize import OllamaTextVectorizer + +ollama_model = os.environ.get("OLLAMA_MODEL", "nomic-embed-text") + +try: + ollama = OllamaTextVectorizer(model=ollama_model) + + test = ollama.embed("This is a test sentence.") + print("Vector dimensions:", len(test)) + print(test[:10]) +except (ImportError, ConnectionError, ValueError) as exc: + print("Skipping Ollama example:", exc) + ollama = None + +``` + + +```python +if ollama is not None: + embeddings = ollama.embed_many(sentences, batch_size=2) + print("Number of embeddings:", len(embeddings)) + print("Vector dimensions:", len(embeddings[0])) +else: + print("Skipping: run the Ollama cell above with a running Ollama server and pulled model.") + +``` + + +```python +if ollama is not None: + embeddings = await ollama.aembed_many(sentences, batch_size=2) + print("Number of async embeddings:", len(embeddings)) +else: + print("Skipping: run the Ollama cell above with a running Ollama server and pulled model.") + +``` + ### VertexAI [VertexAI](https://cloud.google.com/vertex-ai/docs/generative-ai/embeddings/get-text-embeddings) is GCP's fully-featured AI platform including a number of pretrained LLMs. RedisVL supports using VertexAI to create embeddings from these models. To use VertexAI, you will first need to install the ``google-cloud-aiplatform`` library.