Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

community: Add support for SAP HANA Vector hnsw index creation and advanced filtering #7238

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

cinqisap
Copy link
Contributor

Description
This PR synchronizes the hanavector integration with updates made in the Python version of LangChain (PR #27884 and PR #20821). The following changes have been introduced:

  1. Index Creation Support:

    • Added a new function, createHnswIndex, to hanavector.ts. This function facilitates the creation of indexes for SAP HANA Vector, improving usability and alignment with Python capabilities.
  2. Advanced Filtering Support:

    • Introduced support for advanced filtering operations. The newly supported operators are:
      • Equality and Comparison: $eq, $ne, $gt, $gte, $lt, $lte
      • Range and Membership: $between, $in, $nin
      • Pattern Matching: $like
      • Logical Operations: $and, $or
    • These operators enable users to perform more complex filter operations on metadata column.

Issue: No associated issue.

Dependencies: No new dependencies were introduced in this PR.

Twitter handle: @sapopensource


Changed integration main file

  • libs/langchain-community/src/vectorstores/hanavector.ts

Integration tests

  • libs/langchain-community/src/vectorstores/tests/hanavector.int.test.ts

Examples

  • examples/src/indexes/vector_stores/hana_vector/

Documentation

  • docs/core_docs/docs/integrations/vectorstores/hanavector.mdx

Testing

  • Integration tests and examples were run successfully.
  • Access credentials for running the integration tests can be provided to maintainers upon request.

Copy link

vercel bot commented Nov 21, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchainjs-docs ✅ Ready (Inspect) Visit Preview Nov 27, 2024 8:48am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ⬜️ Ignored (Inspect) Nov 27, 2024 8:48am

@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. auto:documentation Changes to documentation and examples, like .md, .rst, .ipynb files. Changes to the docs/ folder auto:improvement Medium size change to existing code to handle new use-cases labels Nov 21, 2024
@@ -58,7 +122,7 @@ export class HanaDB extends VectorStore {

private vectorColumnLength: number;

declare FilterType: Filter;
Copy link
Collaborator

Choose a reason for hiding this comment

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

You'll still want this for methods on the superclass

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for pointing it out! I added this declaration and used it in methods.

Copy link
Collaborator

@jacoblee93 jacoblee93 left a comment

Choose a reason for hiding this comment

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

Looks nice! One small comment. I'm also not familiar with SAP Hana syntax but would just ask that you scan for any injection-type attacks in the code.

@dosubot dosubot bot added the lgtm PRs that are ready to be merged as-is label Nov 22, 2024
@jacoblee93 jacoblee93 added the hold On hold label Nov 22, 2024
@jacoblee93
Copy link
Collaborator

Seems you're failing the new unit tests:

Summary of all failing tests
FAIL src/vectorstores/tests/hanavector.test.ts
  ● Sanity check tests › should sanitize int with illegal value

    expect(received).toContain(expected) // indexOf

    Expected substring: "must not be smaller than -1"
    Received string:    "Value (NaN) must not be smaller than 0"

       8 |       // eslint-disable-next-line @typescript-eslint/no-explicit-any
       9 |     } catch (error: any) {
    > 10 |       expect(error.message).toContain("must not be smaller than -1");
         |                             ^
      11 |     }
      12 |   });
      13 |

      at Object.toContain (src/vectorstores/tests/hanavector.test.ts:10:29)

  ● Sanity check tests › should sanitize int with negative values

    Value (-1) must not be smaller than 0

      243 |     const value = parseInt(inputInt.toString(), 10);
      244 |     if (Number.isNaN(value) || value < lowerBound) {
    > 245 |       throw new Error(
          |             ^
      246 |         `Value (${value}) must not be smaller than ${lowerBound}`
      247 |       );
      248 |     }

      at Function.sanitizeInt (src/vectorstores/hanavector.ts:245:13)
      at Object.sanitizeInt (src/vectorstores/tests/hanavector.test.ts:20:19)

  ● Sanity check tests › should sanitize int with illegal negative value

    expect(received).toContain(expected) // indexOf

    Expected substring: "must not be smaller than -1"
    Received string:    "Value (-2) must not be smaller than 0"

      27 |       // eslint-disable-next-line @typescript-eslint/no-explicit-any
      28 |     } catch (error: any) {
    > 29 |       expect(error.message).toContain("must not be smaller than -1");
         |                             ^
      30 |     }
      31 |   });
      32 |

      at Object.toContain (src/vectorstores/tests/hanavector.test.ts:29:29)


Test Suites: 1 failed, 3 skipped, 63 passed, 64 of 67 total
Tests:       3 failed, 7 skipped, 223 passed, 233 total
Snapshots:   6 passed, 6 total
Time:        22.836 s
Ran all test suites.

@jacoblee93 jacoblee93 added the hold On hold label Nov 25, 2024
@cinqisap
Copy link
Contributor Author

@jacoblee93 Hi Jacob, I've adjusted the unit tests for current sanitization methods.

@cinqisap
Copy link
Contributor Author

Looks nice! One small comment. I'm also not familiar with SAP Hana syntax but would just ask that you scan for any injection-type attacks in the code.

Hi Jacob, I am currently "human-scanning" the source code. It looks well protected against SQL injections since we have input sanitization functions and parameterized the SQL statement. I am also trying to provide the tool-scan result if possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:documentation Changes to documentation and examples, like .md, .rst, .ipynb files. Changes to the docs/ folder auto:improvement Medium size change to existing code to handle new use-cases hold On hold lgtm PRs that are ready to be merged as-is size:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants