Skip to main content

SQL-style semantic query language and retrieval middleware for Agents & RAG

Project description

NLQL

PyPI version Python License: MIT Documentation

English · 简体中文 · 在线文档

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

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
  • Explainableengine.explain() prints the query plan

Installation

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:

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/

More examples in the examples/ directory.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_nlql-0.3.1.tar.gz (216.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_nlql-0.3.1-py3-none-any.whl (106.5 kB view details)

Uploaded Python 3

File details

Details for the file python_nlql-0.3.1.tar.gz.

File metadata

  • Download URL: python_nlql-0.3.1.tar.gz
  • Upload date:
  • Size: 216.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for python_nlql-0.3.1.tar.gz
Algorithm Hash digest
SHA256 881ef9cc49f949c50df0a602d710272949fb16d5cce0e2764c4772ebe406efa8
MD5 53b43ede1f010809d54463cf7bb354fd
BLAKE2b-256 101214c00ae50acae9300daa1608d25927f11737d76d879b91e06246f7e86cb7

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_nlql-0.3.1.tar.gz:

Publisher: publish.yml on natural-language-query-language/python-nlql

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file python_nlql-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: python_nlql-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 106.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for python_nlql-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 72bf66e37a15d5b2a5713dab952230a8bf01d272a8c0fb910165e394e8e7557e
MD5 804290fa58fd0b48b12821fb3b373043
BLAKE2b-256 ed21ff6fe33b365b0d91407a25f1995cbf532c8ad19527eeb58c457b2c6ae6ec

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_nlql-0.3.1-py3-none-any.whl:

Publisher: publish.yml on natural-language-query-language/python-nlql

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page