Metadata-Version: 2.4
Name: python-nlql
Version: 0.3.3
Summary: SQL-style semantic query language and retrieval middleware for Agents & RAG
Project-URL: Repository, https://github.com/natural-language-query-language/python-nlql
Author: Okysu
License: MIT
License-File: LICENSE
Keywords: agent,llm,nlp,query-language,rag,semantic-search,vector-search
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Text Processing :: Linguistic
Requires-Python: >=3.11
Requires-Dist: httpx>=0.27
Requires-Dist: lark>=1.1.0
Requires-Dist: numpy>=2.1
Provides-Extra: chroma
Requires-Dist: chromadb>=0.4.0; extra == 'chroma'
Provides-Extra: dev
Requires-Dist: mypy>=1.7.0; extra == 'dev'
Requires-Dist: pytest-cov>=4.1.0; extra == 'dev'
Requires-Dist: pytest>=7.4.0; extra == 'dev'
Requires-Dist: ruff>=0.1.0; extra == 'dev'
Provides-Extra: docs
Requires-Dist: mkdocs-material>=9.5.0; extra == 'docs'
Requires-Dist: mkdocs-static-i18n>=1.2.0; extra == 'docs'
Requires-Dist: mkdocs>=1.6.0; extra == 'docs'
Requires-Dist: mkdocstrings[python]>=0.26.0; extra == 'docs'
Provides-Extra: faiss
Requires-Dist: faiss-cpu>=1.7.0; extra == 'faiss'
Provides-Extra: hnsw
Requires-Dist: hnswlib>=0.8.0; extra == 'hnsw'
Provides-Extra: loaders
Requires-Dist: pypdf>=4.0; extra == 'loaders'
Requires-Dist: python-docx>=1.1; extra == 'loaders'
Provides-Extra: local
Requires-Dist: sentence-transformers>=2.2.0; extra == 'local'
Provides-Extra: pgvector
Requires-Dist: pgvector>=0.2.0; extra == 'pgvector'
Requires-Dist: psycopg[binary]>=3.1; extra == 'pgvector'
Provides-Extra: qdrant
Requires-Dist: qdrant-client>=1.7.0; extra == 'qdrant'
Provides-Extra: segment
Requires-Dist: pysbd>=0.3.4; extra == 'segment'
Description-Content-Type: text/markdown

# NLQL

[![PyPI version](https://img.shields.io/pypi/v/python-nlql.svg?label=pypi)](https://pypi.org/project/python-nlql/)
[![Python](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
[![Documentation](https://img.shields.io/badge/docs-online-blue.svg)](https://natural-language-query-language.github.io/python-nlql/)

**English** · [简体中文](README.zh-CN.md) · [在线文档](https://natural-language-query-language.github.io/python-nlql/)

NLQL lets you do semantic search with SQL-style statements. Relevance scoring, filtering, and sorting live in one query — no more scattered embedding calls and post-processing code.

Built for Agent and RAG applications: the query itself is structured data, usable directly as an LLM tool-call payload.

## What it looks like

```python
import nlql

engine = nlql.Engine(nlql.embed.FakeEmbedder())  # or OpenAIEmbedder, or any Embedder
engine.add_text("AI agents plan tasks and call tools.", metadata={"status": "published"})
engine.add_text("Banana bread needs flour and sugar.", metadata={"status": "draft"})

for unit in engine.search('''
    SELECT SENTENCE
    LET rel = SIMILARITY(content, "autonomous agents")
    WHERE rel >= 0.2 AND meta.status == "published"
    ORDER BY rel DESC
    LIMIT 5
'''):
    print(f"{unit.scores['rel']:+.3f}  {unit.content}")
```

The statement reads almost like SQL: `SELECT` sets the return granularity, `LET` computes relevance, `WHERE` filters, `ORDER BY` / `LIMIT` sort and cap.

## Features

- **One statement, full intent** — relevance, filtering, and sorting in one place, not scattered across business code
- **Three ways to write, identical results** — SQL statement, Python chained builder, or JSON IR; all compile to the same internal representation
- **Pluggable backends** — built-in store works out of the box; switch to Qdrant / Faiss / Chroma / HnswLib / pgvector with one line
- **Two-stage retrieval** — attach a reranker after recall for higher accuracy
- **Multimodal** — text and images share one vector space; retrieve images with text
- **Explainable** — `engine.explain()` prints the query plan

## Installation

```bash
pip install python-nlql
```

Optional extras:

| Command | Purpose |
|---|---|
| `pip install "python-nlql[faiss]"` | Faiss backend |
| `pip install "python-nlql[hnsw]"` | HnswLib backend (for large-scale data) |
| `pip install "python-nlql[qdrant]"` | Qdrant backend |
| `pip install "python-nlql[chroma]"` | Chroma backend |
| `pip install "python-nlql[pgvector]"` | Postgres + pgvector backend |
| `pip install "python-nlql[local]"` | local sentence-transformers / CLIP / cross-encoder |
| `pip install "python-nlql[loaders]"` | DOCX / PDF file loaders |

## Switching backends

One line; ingestion and query code stay the same:

```python
from nlql.store.qdrant_store import QdrantStore
engine = nlql.Engine(embedder, store=QdrantStore(location=":memory:"))
```

## Documentation

Full docs, tutorials, and API reference: **https://natural-language-query-language.github.io/python-nlql/en/**

- [Quick start](https://natural-language-query-language.github.io/python-nlql/en/content/tutorials/quickstart/)
- [Design](https://natural-language-query-language.github.io/python-nlql/en/content/concepts/overview/)
- [API reference](https://natural-language-query-language.github.io/python-nlql/en/reference/sdk/)
- [中文文档](https://natural-language-query-language.github.io/python-nlql/)

More examples in the [`examples/`](examples/) directory.

## License

[MIT](LICENSE)
