weaviate / typescript-client

Official Weaviate TypeScript Client
https://www.npmjs.com/package/weaviate-client
BSD 3-Clause "New" or "Revised" License
65 stars 23 forks source link

[BUG] Conditional date filter interpreting Date instance as nil #177

Closed michael-pont closed 2 months ago

michael-pont commented 2 months ago

SDK Version 3.1.3

I receive an error from hybrid query when conditional date filter is enabled. I am able to circumvent the error if I ignore the Typescript error and pass in an iso date string rather than a Date object.

WeaviateQueryError: Query call with protocol gRPC failed with message:
/weaviate.v1.Weaviate/Search UNKNOWN: unknown value type <nil>
    at node_modules/weaviate-client/dist/node/cjs/grpc/searcher.js:43:19

Here is code for the query

  const filterValues: FilterValue[] = [
    collection.filter.byProperty('accountId').equal(accountId),
  ]

  if (isSearchOpenJobsOnly) {
    filterValues.push(
      collection.filter.byProperty('jobOpeningClosed').equal(false),
        // This works
        // eslint-disable-next-line @typescript-eslint/ban-ts-comment
        //@ts-ignore
      collection.filter
        .byProperty('lastSeenAt')
        .greaterOrEqual(dayjs().subtract(3, 'weeks').toISOString())
    )
     // The following doesn't work but is not showing type error (Date expected)
      collection.filter
        .byProperty('lastSeenAt')
        .greaterOrEqual(dayjs().subtract(3, 'weeks').toDate())
    )
  }

    response = await collection.query.hybrid(question, {
      alpha: 0.25,
      fusionType: 'RelativeScore',
      queryProperties: ['title', 'description'],
      limit,
      filters: Filters.and(...filterValues),
      returnMetadata: ['score'],
      returnProperties,
    })

From the schema (I deleted other irrelevant properties). The property of focus is lastSeenAt

import { configure, type CollectionConfigCreate } from 'weaviate-client'
import { CustomClassName } from '../types'
import { JobClass } from 'services/common/src/models/jobData'

const className: CustomClassName = CustomClassName.JOB_OPENING
export const JobPostClass: CollectionConfigCreate = {
  name: className,
  description: 'A class holding scoped information about an account',
  multiTenancy: configure.multiTenancy({ enabled: false }),
  vectorizers: configure.vectorizer.text2VecOpenAI({
    sourceProperties: [
      'title',
      'description',
      'location',
      'tags',
    ],
    vectorIndexConfig: configure.vectorIndex.hnsw(),
    model: 'text-embedding-3-small',
    dimensions: 1536,
    type: 'text',
  }),
  generative: configure.generative.openAI({
    model: 'gpt-3.5-turbo',
    temperature: 0,
  }),
  properties: [
    {
      name: 'accountId',
      description: 'The account id', // No cross-reference because querying from tenant to non tenant is not possible
      dataType: 'uuid',
    },
    {
      name: 'jobOpeningClosed',
      description: 'Whether the job opening is closed',
      dataType: 'boolean',
    },
    {
      name: 'firstSeenAt',
      description: 'The first seen date of the job opening',
      dataType: 'date',
    },
    {
      name: 'lastSeenAt',
      description: 'The last seen date of the job opening',
      dataType: 'date',
    },
    {
      name: 'lastProcessedAt',
      description: 'The last processed date of the job opening',
      dataType: 'date',
    },
  ],
}
tsmith023 commented 2 months ago

Hi @michael-pont, thanks for raising this! I can confirm that there's a bug in the SDK whereby the date filter is not being parsed to the gRPC message appropriately I will open a PR now and there will be a patch release this week with other bug fixes. Cheers 😁

michael-pont commented 2 months ago

Thanks for the quick fix!