# Setup Qyver

### **Getting Started with Qyver: Installation & Example**

**Install the Qyver Library**

To use Qyver, install the package via `pip`.

```python
%pip install qyver
```

**As a Python Script:**\
Ensure your Python version is between **3.10.x and 3.12.x**:

```
$ python -V
Python 3.10.9
```

If your Python version is outside this range, consider using [**pyenv**](https://github.com/pyenv/pyenv) to manage it.

**Upgrade `pip` and install Qyver:**

```
$ python -m pip install --upgrade pip
$ python -m pip install qyver
```

***

#### **Running an Example**

{% hint style="info" %}
The first run may take longer as it downloads the necessary embedding model.
{% endhint %}

```
import json
import os
from qyver import framework as sl

# Define the product schema
class Product(sl.Schema):
    id: sl.IdField
    description: sl.String
    rating: sl.Integer

product = Product()

# Define embedding spaces
description_space = sl.TextSimilaritySpace(
    text=product.description, model="Alibaba-NLP/gte-large-en-v1.5"
)
rating_space = sl.NumberSpace(
    number=product.rating, min_value=1, max_value=5, mode=sl.Mode.MAXIMUM
)
index = sl.Index([description_space, rating_space], fields=[product.rating])

# Define query parameters, allowing natural language interpretation
query = (
    sl.Query(
        index,
        weights={
            description_space: sl.Param("description_weight"),
            rating_space: sl.Param("rating_weight"),
        },
    )
    .find(product)
    .similar(
        description_space,
        sl.Param(
            "description_query",
            description="The text in the user's query that refers to product descriptions.",
        ),
    )
    .limit(sl.Param("limit"))
    .with_natural_query(
        sl.Param("natural_language_query"),
        sl.OpenAIClientConfig(api_key=os.environ["OPEN_AI_API_KEY"], model="gpt-4o")
    )
)

# Run the app in-memory (supports server & Apache Spark executors too!)
source = sl.InMemorySource(product)
executor = sl.InMemoryExecutor(sources=[source], indices=[index])
app = executor.run()

# Ingest product data
source.put([
    {"id": 1, "description": "Budget toothbrush in black color. Just what you need.", "rating": 1},
    {"id": 2, "description": "High-end toothbrush created with no compromises.", "rating": 5},
    {"id": 3, "description": "A toothbrush created for the smart 21st-century man.", "rating": 3},
])

# Execute a query
result = app.query(query, natural_query="best toothbrushes", limit=1)

# Inspect extracted parameters
print(json.dumps(result.knn_params, indent=2))

# Display results (returns the highest-rated product)
result.to_pandas()

```

This example showcases **multi-attribute vector search**, combining **text embeddings and numerical rankings** for better retrieval accuracy.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://qyverlabs.gitbook.io/qyverlabs-docs/getting-started/setup.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
