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.0.tar.gz (206.9 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.0-py3-none-any.whl (105.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: python_nlql-0.3.0.tar.gz
  • Upload date:
  • Size: 206.9 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.0.tar.gz
Algorithm Hash digest
SHA256 bb2bf86ae7a81e7b2325e104f16edaf9f737d5d8a21cf1aab064fd7e192989d0
MD5 5e38402176b11eb1fc27b5c4272e744d
BLAKE2b-256 9c1cf524c376df027b953837cb9905b9363e435aa202404c6e3edb5add65aa5c

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_nlql-0.3.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: python_nlql-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 105.6 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 665ac515e866f70f791687c8ee9cc00be7b0d081904e9d60b12ca866ca1b2817
MD5 96b4f6f732e42adfbff08ff3b3d9a131
BLAKE2b-256 025a4a98b2801ba3513892b77a0d86bfd599bc56d91a405291d49a7b327f564e

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_nlql-0.3.0-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