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

MariaDB vector store implementation. #7360

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

rusher
Copy link

@rusher rusher commented Dec 13, 2024

Description

This is the MariaDB vectorstore implementation. see https://mariadb.org/projects/mariadb-vector/

Key Features

  • provide mariadb implementation to store and request embeddings
  • provide a filter unifying proposal

Test

  • test cases added

Filtering proposal

This PR contains a proposal to unify filtering data. I might have not understood stuctured query well, but goal of this framework is to permit unifying behavior and it doesn't feel this part has succeed in it.

I'll detail what i've submitted, i'll let you judge if accurate or not.
There is now a new package "@langchain/core/filter"

an example of database filter implementation:

class TestFilterExpressionConverter
  extends BaseFilterExpressionConverter
  implements FilterExpressionConverter
{
  constructor() {
    super();
  }

  convertExpression(expression: Expression): string {
    return super.convertExpression(expression);
  }

  convertExpressionToContext(expression: Expression, context: StringBuilder): void {
    super.convertOperandToContext(expression.left, context);
    super.convertSymbolToContext(expression, context);
    super.convertOperandToContext(expression.right!, context);
  }

  convertKeyToContext(key: Key, context: StringBuilder): void {
    context.append(`'$.${key.key}'`);
  }

  writeValueRangeStart(_listValue: Value, context: StringBuilder): void {
    context.append("[");
  }

  writeValueRangeEnd(_listValue: Value, context: StringBuilder): void {
    context.append("]");
  }

  writeGroupStart(_group: Group, context: StringBuilder): void {
    context.append("(");
  }

  writeGroupEnd(_group: Group, context: StringBuilder): void {
    context.append(")");
  }
}

A builder permit to create the filter, and vectorstore implementation will convert it to expected format :

const b = new FilterExpressionBuilder();
const impl = new TestFilterExpressionConverter();

let exp = b.eq("a", 2015); 
console.log(impl.convertExpression(exp));
// "'$.a' = 2015"


exp = b.in("a", [2015, 2018]); 
console.log(impl.convertExpression(exp));
// "'$.a' IN [2015,2018]"

// name = 'martin' AND (firstname = 'john' OR firstname = 'jack')
exp = b.and(
            b.eq("name", "martin"),
            b.group(b.or(b.eq("firstname", "john"), b.eq("firstname", "jack")))
        ); 
console.log(impl.convertExpression(exp));
// "'$.name' = 'martin' AND '$.firstname' = 'john'"

// the opposite
exp = b.not(
          b.and(
            b.eq("name", "martin"),
            b.group(b.or(b.eq("firstname", "john"), b.eq("firstname", "jack")))
          )
        ); 
console.log(impl.convertExpression(exp));
// "'$.name' != 'martin' OR ('$.firstname' != 'john' AND '$.firstname' != 'jack')"

(Ideally, a text parser using antlr to generate the expression from a standardized query would next the next step)

When requiring the corresponding SQL to a filter expression, each vector store needs to implement a filter implementation, extending BaseFilterExpressionConverter. This prevent SQL injection, unify behavior, and permit any kind of filtering, like IN, NOT, gouping ...

(a database filtering implementation must be probably maximum 20 significant lines of code, mainly because each database use his specific JSON functions)

@dosubot dosubot bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Dec 13, 2024
Copy link

vercel bot commented Dec 13, 2024

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

Name Status Preview Comments Updated (UTC)
langchainjs-docs ❌ Failed (Inspect) Dec 13, 2024 2:45pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ⬜️ Ignored (Inspect) Dec 13, 2024 2:45pm

@dosubot dosubot bot added auto:documentation Changes to documentation and examples, like .md, .rst, .ipynb files. Changes to the docs/ folder auto:enhancement A large net-new component, integration, or chain. Use sparingly. The largest features labels Dec 13, 2024
@rusher
Copy link
Author

rusher commented Dec 19, 2024

Can i still help to get this PR merged ? about the vercel failure, i cannot have access to it. so i leave it to you to indicate what's wrong

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:enhancement A large net-new component, integration, or chain. Use sparingly. The largest features size:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant