Metadata-Version: 2.4
Name: venra
Version: 0.1.8
Summary: Venra provides a simple, high-level api for vespa.ai.
Project-URL: Homepage, https://pypi.org/project/venra/
Project-URL: Repository, https://github.com/codycollier/venra
Author-email: Cody Collier <cmcollier@gmail.com>
License: The MIT License (MIT)
        
        Copyright (c) 2022 Cody Collier
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: artificial intelligence,information retrieval,machine learning,search
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10
Requires-Dist: requests
Provides-Extra: examples
Provides-Extra: test
Requires-Dist: pytest; extra == 'test'
Description-Content-Type: text/markdown

## venra

[![Project Status: WIP](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
![Tests](https://github.com/codycollier/venra/workflows/Tests/badge.svg)
[![PyPI version](https://badge.fury.io/py/venra.svg)](https://badge.fury.io/py/venra)


Venra provides a simple, high-level api for [vespa.ai](https://vespa.ai).

Venra targets subsets of Vespa's query, document, and system apis. It aims to 
encapsulate the complexity of dealing with the Vespa http interfaces, response
behaviors, and json responses for common client tasks.

Venra is well suited for web backends, command line tools, and enrichment
programs which need to retrieve, process, and update documents.


```python
import venra

qdata = {}
qdata["yql"] = "select * from sources awesome_docs;"
response = venra.query.search(qdata)

docs = venra.query.extract_docs(response)
for r, doc in enumerate(docs):
    print(f"rank: {r} >> {doc.some_id} title: {doc.title}")
```

Note: This library is under active development and the api could change in the future.



### Installation

```bash
$ pip install venra
```


### Usage


Basic Query:

```python

import venra

# Build query
qdata = {}
qdata["yql"] = "select * from sources baz;"

# Run query
response = venra.query.search(qdata)

# Extract results via helpers
metrics = venra.query.extract_metrics(response)
docs = venra.query.extract_docs(response)

```


User Query and Grouping:
```python

from pprint import pprint

from venra import config as vconfig
from venra import query as vquery


# Configure
user_query = "machine learning"
vconfig.vespa_host_app = "http://localhost:8080"

# Build query including a grouping
qdata = {}
qdata["yql"] = "select post_id, post_date from sources baz where userQuery()"
qdata["yql"] += f" | all(group(time.date(post_date)) order(-max(post_date)) max(32) each(output(count())) as(day_counts) );"
qdata["hits"] = 10
qdata["timeout"] = "3300ms"
qdata["model.queryString"] = user_query
qdata["model.type"] = "weakAnd"
qdata["presentation.summary"] = "full"
qdata["presentation.timing"] = "true"

# Run query
response = vquery.search(qdata)

# Extract results via helpers
metrics = vquery.extract_metrics(response)
groups = vquery.extract_groups(response)
myfacet = vquery.extract_group_pairs(groups, "day_counts", "count()")
docs = vquery.extract_docs(response)

# Query results ready for use in app
pprint(metrics)
pprint(myfacet)
pprint(docs)
```


