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.3.tar.gz (218.1 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.3-py3-none-any.whl (108.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: python_nlql-0.3.3.tar.gz
  • Upload date:
  • Size: 218.1 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.3.tar.gz
Algorithm Hash digest
SHA256 a7720edea5635faa1b0946690c77055f7e35abd966f6ccfae859ca22a17b0030
MD5 573efc17ed0bc1b7b35455596ee1faab
BLAKE2b-256 1abf0b46c46a0eb9fda927b070388d86383d16a126444df741c62669f2fe6bd4

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: python_nlql-0.3.3-py3-none-any.whl
  • Upload date:
  • Size: 108.8 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 79265e52e7e307b276e14f29184a250c8ac87557eb4e73acacdc021009549cd7
MD5 1cc173a5a98659f33579d435b1125981
BLAKE2b-256 3041401855f56ce1c80534ac9a615fe863cf149f54748aede2215b4f78b18a8a

See more details on using hashes here.

Provenance

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