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

📦 NEW: add filters support #78

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

Conversation

saqibameen
Copy link
Member

@saqibameen saqibameen commented Jan 24, 2025

Description

Add support for optional array of filters to narrow down the search results.

type FilterOperator = 'Eq' | 'NotEq' | 'In' | 'NotIn' | 'And' | 'Or';
type FilterConnective = 'And' | 'Or';
type FilterValue = string | string[];
type MemoryFilters = [FilterOperator | FilterConnective, FilterValue | MemoryFilters][];

Filters can be either:

  • A single condition: ["field", "operator", "value"]
  • A nested structure: ["And"|"Or", MemoryFilters]

Available operators: "Eq", "NotEq", "In", "NotIn", "And", "Or"

Testing

Basic Testing

1- Create a memory

const memory = await langbase.memory.create({ name: 'test-memory' })

2- Upload docs w metadata

Keep the content same for each document.

// Document 1
...
    meta: { author: 'AuthorA', category: 'Category1' },
...

// Document 1 with different name.  (i.e., content should be same)
...
    meta: { author: 'AuthorB', category: 'Category1' },
...

3- Retrieve:

 query: 'Relevant query',
  memory: [{ name: 'test-memory',  filters: ['Eq', ['author', 'AuthorA']] }],
,

This should correctly return the chunks from document 1.

Further Testing

1- Test a complex filter:

 ['And', [
      ['Eq', ['author', 'AuthorA']],
      ['Eq', ['category', 'Category1']],
    ]],

2- Test without setting any filter
3- Test with retrieving on two memories

  memory: [
  { name: 'test-memory',  filters: ['Eq', ['author', 'AuthorA']] }
  { name: 'test-memory2',  filters: ['Eq', ['author', 'AuthorB']] }
  ],

4- Test e2e RAG
5- Test UI (upload/retrieval test)

Docs

Docs: https://github.com/LangbaseInc/docs/pull/166
SDK: #78
API: https://github.com/LangbaseInc/langbase-api/pull/357

Deployment

1- Run test locally
2- Deploy workers
3- Run prod tests

@saqibameen saqibameen requested a review from msaaddev January 24, 2025 05:57
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.

1 participant