Skip to main content

An integration package connecting Superlinked and LangChain

Project description

langchain-superlinked

Integration package that exposes Superlinked retrieval capabilities via the standard LangChain retriever interface. It lets you plug a Superlinked-powered retriever into LangChain RAG pipelines while keeping your vector storage and schema choices flexible.

Install

pip install -U langchain-superlinked superlinked

Quickstart

import superlinked.framework as sl
from langchain_superlinked import SuperlinkedRetriever

class DocumentSchema(sl.Schema):
    id: sl.IdField
    content: sl.String

doc_schema = DocumentSchema()
text_space = sl.TextSimilaritySpace(text=doc_schema.content, model="sentence-transformers/all-MiniLM-L6-v2")
index = sl.Index([text_space])
query = (
    sl.Query(index)
    .find(doc_schema)
    .similar(text_space.text, sl.Param("query_text"))
    .select([doc_schema.content])
)

source = sl.InMemorySource(schema=doc_schema)
executor = sl.InMemoryExecutor(sources=[source], indices=[index])
app = executor.run()
source.put([
    {"id": "1", "content": "Machine learning processes data efficiently."},
    {"id": "2", "content": "NLP understands human language."},
])

retriever = SuperlinkedRetriever(sl_client=app, sl_query=query, page_content_field="content")
docs = retriever.invoke("artificial intelligence", k=2)

See more end-to-end examples in docs/.


Local development

Prerequisites: Python 3.10–3.13, uv installed.

  • Setup: uv sync --all-extras --dev && uv run pre-commit install
  • Lint & type-check: uv run ruff check . && uv run ruff format --check . && uv run mypy langchain_superlinked
  • Unit tests: make test
  • Integration tests: make integration_tests (skips if langchain_tests isn’t installed)
  • Smoke test: make smoke
  • Run examples: uv run python docs/quickstart_examples.py

CI/CD overview

On push/PR to main, GitHub Actions runs (matrix: 3.10/3.11/3.12):

  • Lint: ruff check . and ruff format --check .
  • Type-check: mypy langchain_superlinked
  • Tests: unit (network disabled) and integration (skips if standard tests unavailable)
  • Smoke test: imports the package and symbols
  • Build: python -m build to produce sdist and wheel (no publish)

Workflow file: .github/workflows/ci.yml.


Releasing

  • Preferred: tag-based OIDC publish
    • Ensure PyPI Trusted Publisher is configured for this repo.
    • Bump version in pyproject.toml using semantic versioning.
    • Tag and push: git tag vX.Y.Z && git push origin vX.Y.Z
    • CI will build and publish automatically.
  • Manual (fallback):
    • Build artifacts: make dist
    • Validate: uv run twine check dist/*
    • Publish to PyPI: uv run twine upload -r pypi dist/*

After publish, open/refresh the docs PR in the LangChain monorepo to reference the new version if needed. See LangChain’s integration guide for the process: How to contribute an integration.


Implementation overview

  • Primary entrypoint: langchain_superlinked/retrievers.py exposes SuperlinkedRetriever, a BaseRetriever.
  • Construction:
    • sl_client: Superlinked App (e.g., from InMemoryExecutor.run()).
    • sl_query: Superlinked QueryDescriptor built via sl.Query(...).find(...).similar(...).select(...).
    • page_content_field: field from Superlinked results mapped to Document.page_content.
    • Optional metadata_fields: copied into Document.metadata in addition to the always-present id.
  • Behavior:
    • Accepts runtime parameters (e.g., k, weights, filters) and forwards them to the Superlinked query.
    • Handles missing fields gracefully; returns an empty list on upstream exceptions.

Scope and non-goals

This package aims to be the minimal, well-typed LangChain integration layer for Superlinked retrievers. It intentionally does not include:

  • Dynamic schema inference or auto-generation for arbitrary datasets. Rationale: datasets vary widely; a robust solution requires additional assumptions (typing, transforms, index strategy), which goes beyond the minimal integration. We recommend implementing this in a separate helper package or cookbook code layered on top (e.g., “schema builders” that emit Superlinked schemas and indices for your domain). The examples in docs/ illustrate patterns for composing spaces (text, categorical, numeric, recency) that such builders could automate.
  • Non-retriever integrations (custom LLMs, embeddings, caches, loaders). These can live in separate packages if needed.

If you have concrete requirements for dynamic schema construction, please open an issue with sample data and desired retrieval behavior so we can discuss an extensible approach that stays decoupled from the core integration.


Links

License

MIT (see LICENSE)

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

langchain_superlinked-0.1.0.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

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

langchain_superlinked-0.1.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file langchain_superlinked-0.1.0.tar.gz.

File metadata

  • Download URL: langchain_superlinked-0.1.0.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for langchain_superlinked-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a373938a63b666e8182f3050a0b45bbfa9df04830334a5eb4ae8632fea76cdf1
MD5 f50f04e5fe73090b535739d5a2d8c930
BLAKE2b-256 28c9dc3a0a0d0d85870a86e23465a5d4567fa81d611d9a7a64e35cfccc385695

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_superlinked-0.1.0.tar.gz:

Publisher: publish.yml on superlinked/langchain-superlinked

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

File details

Details for the file langchain_superlinked-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_superlinked-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a6baeee533af69817df5ea83117a0606a3a06c198b09fe386988784bbc394388
MD5 06399ff267acb24bedc7d1960205cba3
BLAKE2b-256 73270bb7b72eeef9173a26be4d2a2c253f54ffb1d6e9149ea80012328b6db362

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_superlinked-0.1.0-py3-none-any.whl:

Publisher: publish.yml on superlinked/langchain-superlinked

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