Skip to content

feat(langchain): add CoordinodeGraph.keyword_search()#41

Merged
polaz merged 2 commits intomainfrom
feat/#22-langchain-keyword-search
Apr 16, 2026
Merged

feat(langchain): add CoordinodeGraph.keyword_search()#41
polaz merged 2 commits intomainfrom
feat/#22-langchain-keyword-search

Conversation

@polaz
Copy link
Copy Markdown
Member

@polaz polaz commented Apr 16, 2026

Summary

  • Add CoordinodeGraph.keyword_search() to langchain-coordinode
  • Wraps CoordinodeClient.text_search() (BM25 full-text search)
  • Returns list[dict] with node_id, score, snippet keys
  • Supports fuzzy and language kwargs forwarded to the underlying client
  • Gracefully returns [] when the injected client has no text_search method (e.g. bare coordinode-embedded LocalClient)

Test plan

  • 7 unit tests covering: happy path, parameter forwarding, defaults (label=Chunk, k=5), missing method fallback, empty results, snippet preservation
  • All 61 unit tests pass, ruff clean

Closes #22

Wraps CoordinodeClient.text_search() to expose BM25 full-text search
via the LangChain GraphStore adapter. Returns list[dict] with
node_id/score/snippet keys, consistent with similarity_search() output.

Gracefully returns [] when the injected client has no text_search method
(e.g. bare coordinode-embedded LocalClient) to maintain parity with the
existing similarity_search() fallback pattern.

Closes #22
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 16, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 8d8bb9f4-8c4a-4fba-95b3-24febce295ba

📥 Commits

Reviewing files that changed from the base of the PR and between 8169085 and 81633f9.

📒 Files selected for processing (2)
  • langchain-coordinode/langchain_coordinode/graph.py
  • tests/unit/test_langchain_graph.py

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added keyword search for graph nodes with configurable result limits, fuzzy matching, and language-specific processing; gracefully returns empty results when unavailable.
  • Tests

    • Added unit tests verifying output shape, parameter forwarding, defaults, client compatibility, and edge-case behaviors.

Walkthrough

Adds CoordinodeGraph.keyword_search(...) which delegates to the client's text_search(...) with runtime capability checking, forwards parameters (label, query, limit, fuzzy, language), and normalizes results to dicts with keys id, score, and snippet. Includes unit tests covering behavior and edge cases.

Changes

Cohort / File(s) Summary
keyword_search() implementation
langchain-coordinode/langchain_coordinode/graph.py
New CoordinodeGraph.keyword_search(query, k=5, label="Chunk", *, fuzzy=False, language="") that checks for text_search support, calls self._client.text_search(label=label, query=query, limit=k, fuzzy=fuzzy, language=language), returns [] if unsupported or no results, and normalizes each result to a dict with keys id (from r.node_id), score, and snippet.
Unit tests
tests/unit/test_langchain_graph.py
New test module TestKeywordSearch with fake clients (one with text_search, one without). Tests validate parameter forwarding (including defaults label="Chunk" and k=5), output shape and content (id, score, snippet), preservation of empty snippets, and graceful behavior when text_search is absent or returns no results.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant CoordinodeGraph
    participant CoordinodeClient
    Caller->>CoordinodeGraph: keyword_search(query, k, label, fuzzy, language)
    CoordinodeGraph->>CoordinodeClient: text_search(label=label, query=query, limit=k, fuzzy=fuzzy, language=language)
    CoordinodeClient-->>CoordinodeGraph: [TextResult...] / []
    CoordinodeGraph->>CoordinodeGraph: normalize -> [{id, score, snippet}, ...] or []
    CoordinodeGraph-->>Caller: list of dict results
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 58.82% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding the keyword_search() method to CoordinodeGraph in the langchain adapter.
Description check ✅ Passed The description is directly related to the changeset, providing a comprehensive summary of the feature, test coverage, and linking to the relevant issue.
Linked Issues check ✅ Passed The PR successfully implements the LangChain adapter requirement from issue #22 by adding CoordinodeGraph.keyword_search() with full parameter forwarding, graceful fallback, and comprehensive unit tests.
Out of Scope Changes check ✅ Passed All changes are in-scope: the new keyword_search() method and its unit tests directly fulfill the LangChain adapter requirement specified in issue #22.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/#22-langchain-keyword-search

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/unit/test_langchain_graph.py`:
- Around line 52-53: The empty close() methods in the test fakes should include
an explicit no-op rationale to satisfy static analysis; update the close()
implementations in tests/unit/test_langchain_graph.py (the fake client classes'
close methods) to include either a one-line docstring or an inline comment like
"no-op for interface parity with real client" so the intent is documented and
the linter stops flagging the empty bodies.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: dfb6cf6b-7517-4328-9ab2-5ed523118fc4

📥 Commits

Reviewing files that changed from the base of the PR and between 75a3c0a and 8169085.

📒 Files selected for processing (2)
  • langchain-coordinode/langchain_coordinode/graph.py
  • tests/unit/test_langchain_graph.py

Comment thread tests/unit/test_langchain_graph.py Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a LangChain adapter convenience API for CoordiNode full-text (BM25) search so LangChain users can run keyword queries through CoordinodeGraph, with unit tests validating behavior using mock clients.

Changes:

  • Add CoordinodeGraph.keyword_search() that wraps an injected client’s text_search() when available.
  • Implement graceful fallback to [] when text_search is not implemented by the injected client.
  • Add unit tests covering result shaping, parameter forwarding, defaults, and empty/fallback cases.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
langchain-coordinode/langchain_coordinode/graph.py Adds keyword_search() API on CoordinodeGraph wrapping text_search() and shaping results.
tests/unit/test_langchain_graph.py Adds mock-based unit tests for keyword_search() behavior and defaults.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread langchain-coordinode/langchain_coordinode/graph.py Outdated
…ilarity_search()

Both search methods now return dicts with "id" as the node identifier key.
Docstring updated to document the cross-method consistency guarantee.
@sonarqubecloud
Copy link
Copy Markdown

@polaz polaz merged commit 35d2f5e into main Apr 16, 2026
8 checks passed
@polaz polaz deleted the feat/#22-langchain-keyword-search branch April 16, 2026 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add text_search() and hybrid_text_vector_search() to CoordinodeClient

2 participants