Skip to content

A DSPy retriever over Loom search #716

Closed

Description

@zlareb1

Company or project name

No response

Component

Python SDK

Use case

DSPy programs retrieve through a retriever module; Loom has adapters for several frameworks (docs/features/integrations/frameworks.md) but none for DSPy.

Describe the solution you'd like

Goal. loom.integrations.dspy: a retriever that calls Loom search (memory and knowledge) and returns passages with their source.

Files to change. #650 (the OpenAI Agents SDK tools) is a worked example of each:

  • sdk/python/loom/integrations/dspy.py and sdk/python/loom/integrations/__init__.py;
  • a dspy extra in sdk/python/pyproject.toml, pinned to a minor range;
  • dspy in SDK_ADAPTER_EXTRAS in the Makefile, so make test-sdk-adapters installs and tests it;
  • the DSPy modules in the mypy ignore_missing_imports list for the framework adapters in the root pyproject.toml;
  • sdk/python/tests/test_dspy.py;
  • a row in the table and a section in docs/features/integrations/frameworks.md, the framework list in docs/features/integrations/index.md, a line in docs/reference/python-sdk.md, and the [dspy] extra in the framework adapters sentence of sdk/python/README.md.

Acceptance criteria

  • Before writing it, say in this issue which DSPy retriever interface the adapter targets and why. DSPy offers more than one way in (a retrieval model set with dspy.configure(rm=…) and read through dspy.Retrieve, or a plain function or dspy.Module that a program calls or hands to dspy.ReAct as a tool), and which one it recommends has changed across releases.
  • Signatures checked against the installed DSPy release; the PR names the version.
  • make test-sdk-adapter-dspy passes (one venv with the extra installed, its tests and mypy --strict), and so does make test-sdk-adapter-dspy SDK_ADAPTERS_PYTHON=3.11 SDK_ADAPTERS_RESOLUTION=lowest-direct, the lowest-deps leg of CI's sdk-python-adapters job, which installs every direct requirement at its lower bound.
  • make test-sdk-adapters, make format-check lint typecheck and .venv/bin/python -m pytest tests/unit/test_sdk_extra_requirements.py -q pass; that test checks that every extra in SDK_ADAPTER_EXTRAS has loom/integrations/<extra>.py and tests/test_<extra>.py.
  • loom/integrations/dspy.py imports the framework inside try/except ImportError and re-raises an ImportError that names pip install 'clickhouse-loom[dspy]', as sdk/python/loom/integrations/openai_agents.py does (lines 31-37). CI's sdk-python-package job checks it with scripts/gates/sdk_wheel_smoke.py, which imports every submodule in a clean venv holding only the wheel and fails on an adapter whose ImportError does not name its extra. Run it locally from an empty dist/:
uv build sdk/python --out-dir dist
uv venv /tmp/sdk-venv
uv pip install --python /tmp/sdk-venv/bin/python dist/*.whl
/tmp/sdk-venv/bin/python scripts/gates/sdk_wheel_smoke.py dist/*.whl
  • The docs checks pass:
.venv/bin/python -m pytest tests/unit/test_doc_links.py tests/unit/test_public_copy.py -q
.venv/bin/python -m scripts.codegen.docs_reference --check

Describe alternatives you've considered

A DSPy program can call the SDK directly inside a custom module; an adapter gives it the retriever interface DSPy already composes.

Where the need comes from

The need is mine, an AI tool helped shape the proposal

Additional context

Start after #696 (the Google ADK memory service) merges, or rebase onto it: it edits frameworks.md, integrations/index.md, python-sdk.md, sdk/python/README.md, SDK_ADAPTER_EXTRAS in the Makefile and both pyproject.toml files.

Size: M (a day or two). Read CONTRIBUTING.md first (signed-off commits), and comment here to say you are working on it.

Activity

  1. added
    enhancement
    help wanted
    on Nov 16, 2026
  2. rahulsjha commented on Nov 20, 2026

    @rahulsjha
    Contributor

    Hi @zlareb1, I'd like to take this one, following #650 as the pattern.

    Plan:

    • sdk/python/loom/integrations/dspy.py: a LoomRM retriever (a dspy.Retrieve module) that calls Loom search over memory and knowledge with k, namespace and optional filters, and returns dspy.Prediction(passages=[...]). Each passage carries its text, score and source (memory id or document and chunk citation), so a DSPy program can cite what it used.
    • The dspy extra pinned to a minor range, dspy in SDK_ADAPTER_EXTRAS, and the DSPy modules in the mypy ignore_missing_imports list.
    • sdk/python/tests/test_dspy.py against a stubbed Loom client: passages and sources come through, k and filters are passed on, an empty result is an empty list, and a search error is raised rather than swallowed.
    • The docs: a row and a section in frameworks.md, the framework list in integrations/index.md, and a line in python-sdk.md.
  3. rahulsjha commented on Nov 20, 2026

    @rahulsjha
    Contributor

    @zlareb1, on the acceptance question of which DSPy retriever interface to target: I checked DSPy 3.5.0 (the current release).

    • dspy.configure(rm=...) read through dspy.Retrieve: still there, but Retrieve.forward keeps only each passage's long_text and returns Prediction(passages=[...]). The sources would be lost, and citing them is the point of this adapter.
    • A plain callable: DSPy's own retriever, dspy.retrievers.Embeddings, is a plain class whose __call__(query) returns dspy.Prediction(passages=..., indices=...). A program calls it in forward, or wraps it in dspy.Tool for dspy.ReAct.

    So the adapter is a plain callable in that shape:

    • LoomKnowledgeRetriever(agent, k=3) and LoomMemoryRetriever(agent, k=3, user_id=...), the same pair and fields as the LangChain retrievers.
    • Calling one returns dspy.Prediction(passages, sources, scores, metadata).
    • acall takes an async Agent.
    • as_tool() returns a dspy.Tool for ReAct, sync or async to match the agent, that returns [source] passage lines.

    The PR is up next, pinned to dspy>=3.5,<3.6.

  4. added
    up-for-grabs
    on Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementhelp wantedup-for-grabs

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions