Giter Site home page Giter Site logo

weaviate / typescript-client Goto Github PK

View Code? Open in Web Editor NEW
54.0 11.0 18.0 2.09 MB

Official Weaviate TypeScript Client

Home Page: https://www.npmjs.com/package/weaviate-ts-client

License: BSD 3-Clause "New" or "Revised" License

TypeScript 98.25% JavaScript 1.36% Shell 0.38%
generative-search image-search neural-search search-engine semantic-search typescript vector-database vector-search weaviate

typescript-client's Introduction

typescript-client's People

Contributors

abhijithchintu avatar aliszka avatar antas-marcin avatar cnadeau avatar dandv avatar dirkkul avatar flipace avatar joshdschneider avatar mloenow avatar parkerduckworth avatar snyk-bot avatar thomashacker avatar tsmith023 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

typescript-client's Issues

Incorrect error message when updating the schema

When updating the schema, the error message swaps the class and property name, e.g.

Error: usage error (422): {"error":[{"message":"class \"authors\": conflict for property \"Article\": already in use or provided multiple times"}]}

For example, when using:

await client.schema
      .propertyCreator()
      .withClassName(className)
      .withProperty(property)
      .do()
      .catch((err: Error) => {
        console.warn(err);
      });

As a side note, I have created a simple CLI tool to update a class using a configuration file, weaviate-class-updater

Add a formatter

We curerntly do not have a formatter for the JS code. I don't have any preferences so please use the most common one :)

This should be added:

In the CI
In precommit

Error: Cannot find module 'graphql-request'

Error on fresh install of "weaviate-ts-client": "^1.4.0", - it's unusable:

/Users/josiahbryan/devel/rubber/backend/node_modules/weaviate-ts-client/dist/index.js:1
Error: Cannot find module 'graphql-request'
Require stack:
- /Users/josiahbryan/devel/rubber/backend/node_modules/weaviate-ts-client/dist/index.js
- /Users/josiahbryan/devel/rubber/backend/src/services/chatbot/utils/graph/node-indexer.js
    at Object.<anonymous> (/Users/josiahbryan/devel/rubber/backend/node_modules/weaviate-ts-client/dist/index.js:1)
    at Generator.next (<anonymous>) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/josiahbryan/devel/rubber/backend/node_modules/weaviate-ts-client/dist/index.js',
    '/Users/josiahbryan/devel/rubber/backend/src/services/chatbot/utils/graph/node-indexer.js'
  ]
}

Node.js v20.5.0

'properties' does not exist in type 'HybridArgs'

I see that properties is included in HybridArgs in 1.3.0, but the following code snippet fails with

Argument of type '{ query: string; alpha: number; properties: string[]; }' is not assignable to parameter of type 'HybridArgs'.
Object literal may only specify known properties, and 'properties' does not exist in type 'HybridArgs'.

import weaviate, { WeaviateClient } from 'weaviate-ts-client';

const client: WeaviateClient = weaviate.client({
  scheme: 'https',
  host: '...',
});

const response = await client.graphql
  .get()
  .withClassName('JeopardyQuestion')
  .withFields('question answer _additional{ score }')
  .withHybrid({
    query: 'Venus',
    properties: ["question"],  // <--
  })
  .do();

Unable to batch DELETE objects by id

Hi there, I am trying to batch DELETE objects by id, but it fails on 1.5.0

`

await this.client.batch
    .objectsBatchDeleter()
    .withClassName('whatever')
    .withWhere({
      path: ['id'],
      operator: 'ContainsAny',
      valueTextArray:[x,y,z],
    })
    .do()

`

The error I am getting is: usage error (422): {"code":606,"message":"match.match.where.operator in body should be one of [And Or Equal Like Not NotEqual GreaterThan GreaterThanEqual LessThan LessThanEqual WithinGeoRange IsNull]"}

Support where filters in classifications

Background

Weaviate allows a set three different where filters in classifications, but the client currently does not take any arguments.

Goals

  • .withSourceWhere() is added to the classification builder
  • .withTrainingSetWhere() is added to the classification builder
  • .withTargetWhere() is added to the classification builder

client.data.checker() returns a function instead of a boolean

const client = weaviate.client({
  scheme: 'https',
  host: 'edu-demo.weaviate.network',
  apiKey: new weaviate.ApiKey('learn-weaviate'),
});

const id = '00ff6900-e64f-5d94-90db-c8cfa3fc851b';

result = await client.data
  .checker()
  .withClassName('JeopardyQuestion')
  .withId(id)
  .do();

console.log(typeof result, `result: ${result}`, JSON.stringify(result));

The output will be this,

function result: t=>{if(t.status>=400)return t.text().then(e=>{let r;try{r=JSON.stringify(JSON.parse(e))}catch{r=e}return Promise.reject(new Error(usage error (${t.status}): ${r}))});if(i)return t.json()} undefined

The object does exist,

result = await client.data
  .getterById()
  .withClassName('JeopardyQuestion')
  .withId(id)
  .do();

console.log(JSON.stringify(result, null, 2));

BTW the tests for checker() lack .withClassName(), which results in a warning, "Usage of objects paths without className is deprecated in Weaviate 1.19.6. Please provide className parameter".

realFetch.call is not a function

The client doesn't work in AWS lambda environment, runtime is Node.js 18.

A call like:

let batcherVectors = client.batch.objectsBatcher();
...
await batcherVectors.do();

crashes with the following error:

| TypeError: realFetch.call is not a function
| at d (.../chatbot/aws/node_modules/.pnpm/[email protected]/node_modules/isomorphic-fetch/fetch-npm-node.js:8:19)
| at Object.post (.../chatbot/aws/node_modules/.pnpm/[email protected][email protected]/node_modules/weaviate-ts-client/dist/index.mjs:1:5955)

This seems connected to the old issue of isomorphic-fetch:
matthew-andrews/isomorphic-fetch#194

Would be nice to use a real fetch in supported environments, like node.js 18 or give us an option to provide a fetch client via parameter to weaviate client.

weaviate-ts-client library error on sveltekit

Hi, I keep getting this error in the weavite-ts-client source:

"Uncaught (in promise) SyntaxError: missing name after . operator"

The view source points out to the line below FIX ME comment as the issue at weaviate-ts-client.js:2365:35

// node_modules/.pnpm/[email protected]/node_modules/graphql/jsutils/instanceOf.mjs var instanceOf = ( /* c8 ignore next 6 */ // FIXME: https://github.com/graphql/graphql-js/issues/2317 globalThis.process && globalThis."development" === "production" ? function instanceOf2(value, constructor) { return value instanceof constructor; } : function instanceOf3(value, constructor) { if (value instanceof constructor) { return true; } ...

I don't know if this is an issue in my end on the specific TS config in Sveltekit or if its in the source for certain since the library seems to work on just a vanilla ts-node set up while failing to work in the sveltekit environment.

Integrate the library with a Fastify Project

Hey I'm trying to integrate the typescript-client with a project made with Fastify

image

I'm creating a plugin but the weaviate variable is always undefined I know this is something related with typescript so I share my tsconfig.json

{ "extends": "fastify-tsconfig", "compilerOptions": { "strict": true, "sourceMap": false, "skipLibCheck": true, "target": "esnext", "module": "CommonJS", "outDir": "./dist", "typeRoots": ["@types"] }, "include": ["src/**/*.ts"] }

Thanks for the help!

422 error on creating classes with references: invalid dataType: reference property to nonexistent class

I am trying to build something similar to the Wikipedia example in typescript and node.
It seems in the npm client, there is no create schema method, and hence I have to create classes async in different API calls, but in doing so I get 422 error: invalid dataType: reference property to a nonexistent class. I am not sure if this is the cause of the problem or something else.

  • There was a related conversation on Weaviate Slack, suggesting changing vectorizier would make it work (for example text2vec-transformers do not work but text2vec-contextionary does. In my case none works.
const schemaClasses = [
   ArticleClass,
   ParagraphClass
]

for await (classObj in schemaClasses){
   await client.schema.classCreator().withClass(classObj)
}

[FR] consistency level for client.data.checker()

For feature parity with Python and so that this example would work:

import weaviate from 'weaviate-ts-client';

const client = weaviate.client({
  scheme: 'http',
  host: 'localhost:8080',
});

const response = await client.data
  .checker()
  .withClassName('MyClass')
  .withId('df48b9f6-ba48-470c-bf6a-57657cb07390')
  .withConsistencyLevel('QUORUM')
  .do();
console.log(response);

Warn when errors occurred during batch operations

I had forgotten to include the OpenAI API key in the headers, and noticed that batch imports appeared to succeed, but no objects were committed to the database.

Turned out that the response to batcher.do() included a result field with the error buried inside. I expected the batcher to throw.

import assert from 'assert';

import weaviate from 'weaviate-ts-client';
import fs from 'fs';
import csv from 'csv-parser';

const client = weaviate.client({
  scheme: 'http',
  host: 'localhost:8080',
  // no OpenAI API key
});

const classDefinition = {
  class: 'JeopardyQuestion',
  description: 'A Jeopardy! question',
  vectorizer: 'text2vec-openai',
};

try {
  await client.schema.classDeleter().withClassName('JeopardyQuestion').do();
} catch { }
finally {
  await client.schema.classCreator().withClass(classDefinition).do();
}

const qs = [
  { question: 'What color?', answer: 'Blue' },
  { question: 'Where?', answer: 'In the sky' },
]

let batcher = client.batch.objectsBatcher();

for (const q of qs)
  batcher = batcher.withObject({
    class: 'JeopardyQuestion',
    properties: q,
  });

const response = await batcher.do();
console.log(response.map(r => r.result.errors.error));  // <-- all objects OK, but nothing written to the DB
batcher = client.batch.objectsBatcher();

const result = await client.graphql.aggregate().withClassName('JeopardyQuestion').withFields('meta { count }').do();
assert.deepEqual(result.data['Aggregate']['JeopardyQuestion'], [{ meta: { count: 2 } }]);

Add support for API keys

With v1.18 weaviate supports API keys to authenticate.

Implementation is straightforward:

  • Accept an API key from user
  • Send it in the header as {authorization: Bearer API_KEY}

Example python PR

Add a linter

We curerntly do not have a linter for the JS code. I don't have any preferences so please use the most common one :)

This should be added:

In the CI
In precommit

Typed class properties

It would be great if we could specify explicit class properties for different classes.

Example:

import type { WeaviateClass } from 'weaviate-ts-client';

interface CustomerMacroProperties {
  title: string;
  text: string;
  clientId: string;
}

const CustomerMacro: WeaviateClass<CustomerMacroProperties> = {
  class: 'CustomerMacro',
  description: 'A Customer macro',
  invertedIndexConfig: {
    indexPropertyLength: true,
    indexNullState: true,
    stopwords: {
      preset: 'none',
    },
  },
  properties: [{
    name: 'title',
    description: 'The title of the macro',
    dataType: ['text'],
  }, {
    name: 'text',
    description: 'The text of the macro',
    dataType: ['text'],
  }, {
    name: 'clientId',
    description: 'The ID of the customer the macro belongs to',
    dataType: ['string'],
    moduleConfig: {
      'text2vec-contextionary': {
        skip: true,
      },
    },
  }],
};

Fix token refresh on unstable connections

On unstable connections, the token refresh can sometimes fail which can results in unauthenticated clients.

To be able to handle these situations, the client should:

  • set a default timeout for auth connections. We used 5s in the python client, this should be plenty
  • make sure that the refresh happens early enough to still be authenticated if it fails. In the python client we refresh 30s before the authentication expires.
  • catch exceptions about timeouts and immediately retry. Note that I saw timeouts and Connection errors (not sure about the names for them here)

With this we should be able to have 3-4 retries. If this is not enough, the connection is too bad.

Python PR with the changes and a test

Complete type definitions

The JavaScript client PR which migrated this client from untyped javascript included some types, but not all of them. Now there are a remainder of any types which should be assigned their proper types, where possible.

A quick way to determine where these changes need to be made can be done by grepping the repo for : any.

Misconfiguration for typescript projects using module node16/nodenext

Hi.

I'm currently working on ESM repo with tsconfig moduleResolution set to node16, and this library has misconfigured type definition that confusing typescript when we try to import default export from the module.

In current configuration, the library's seems to have so-called double-default problem described in typescript repo.

Reproduce

In a project with
package.json "type": "module"
tsconfig.json "moduleResolution": "node16"

While trying to import default export from weaviate-ts-client, typescript's expectation and actual runtime value mismatches

import weaviate from 'weaviate-ts-client';
console.log(weaviate.client); // ts error; Property 'client' does not exist on type

// Typescript expect it to be
// {
//   default: {
//     client: (params: ConnectionParams) => WeaviateClient;
//     ApiKey: typeof ApiKey;
//     AuthUserPasswordCredentials: typeof AuthUserPasswordCredentials;
//     AuthAccessTokenCredentials: typeof AuthAccessTokenCredentials;
//     AuthClientCredentials: typeof AuthClientCredentials;
//     EmbeddedOptions: typeof EmbeddedOptions;
//   };
// }

// But it's actual value in runtime is
// {
//   client: (params: ConnectionParams) => WeaviateClient;
//   ApiKey: typeof ApiKey;
//   AuthUserPasswordCredentials: typeof AuthUserPasswordCredentials;
//   AuthAccessTokenCredentials: typeof AuthAccessTokenCredentials;
//   AuthClientCredentials: typeof AuthClientCredentials;
//   EmbeddedOptions: typeof EmbeddedOptions;
// };

You can see arethetypeswrong also indicates the repo is misconfigured in the exact way as I described above.

It seems like node16's module resolution strategy and typescript's following implementations making a lot of trouble in ecosystem and making quite a bit of confusions all over the place, as you can see from

microsoft/TypeScript#50058
microsoft/TypeScript#49160
vitejs/vite-plugin-react#104

I'm afraid that I can't really tell what's the workaround for this as it's really confusing for me that what's the problem at the first place..

I might be wrong here, so feel free to point me out.
It'd be much appreciated if someone can analyze the details regarding to the problem.

Typescript HeaderInit not defined

I'm getting a type error in my weaviate client constructor saying that string is not the right type:

Type '{ 'X-OpenAI-Api-Key': string | undefined; }' is not assignable to type 'HeadersInit | undefined'.

"headers?: HeadersInit;" appears in index.ts in this repo but is not defined elsewhere in the repo.

Script not exiting when using `AuthUserPasswordCredentials`

When running the exact same script, instantiating the client with AuthUserPasswordCredentials leads to the script not exiting upon completion. For example:

import weaviate, { WeaviateClient } from 'weaviate-ts-client';

const client: WeaviateClient = weaviate.client({
  scheme: "https",
  host: "<wcs instance w OIDC>",
  authClientSecret: new weaviate.AuthUserPasswordCredentials({
    username: "<email>",
    password: "<password>",
  })
});

client
  .schema
  .getter()
  .do()
  .then((res: any) => {
    console.log(res);
  })
  .catch((err: Error) => {
    console.error(err)
  });

Causes it to hang at completion (running with ts-node), whereas authenticating with the API key will work just fine:

import weaviate, { WeaviateClient } from 'weaviate-ts-client';

const client: WeaviateClient = weaviate.client({
  scheme: "https",
  host: "<the same wcs instance w OIDC>",
  headers: {"Authorization": "Bearer <API key>"}
});

client
  .schema
  .getter()
  .do()
  .then((res: any) => {
    console.log(res);
  })
  .catch((err: Error) => {
    console.error(err)
  });

Note: This behaviour (hanging) does not occur when using a WCS instance without authentication turned on, either.

Unknown argument "nearText" on field

v1.3.1

seems nearText is not properly validated although supported.
either raw or api

const query =  '{Get{ Image(limit:3, bm25: {query:"sunglasses"}){url, _additional{score}}}}'

async function nearTextQueryRaw() {
    const res = await client
      .graphql
      .raw()
      .withQuery(query)
      .do();
    console.log(JSON.stringify(res));
    return res;
  }


async function nearTextQuery() {
  const res = await client.graphql
    .get()
    .withClassName('Article')
    .withFields('functional fictional')
    .withNearText({'concepts': ['sun',  'tree']})
    .withLimit(2)
    .do();

  console.log(JSON.stringify(res, null, 2));
  return res
}
ClientError: Unknown argument "nearText" on field "Article" of type "GetObjectsObj". Did you mean "nearVector" or "nearObject"?: {"response":{"errors":[{"locations":[{"column":14,"line":1}],"message":"Unknown argument \"nearText\" on field \"Article\" of type \"GetObjectsObj\". Did you mean \"nearVector\" or \"nearObject\"?","path":null}],"status":200,"headers":{}},"request":{"query":"{Get{Article(nearText:{concepts:[\"sun\",\"tree\"]},limit:2){functional fictional}}}"}}
    at makeRequest (/****/node_modules/weaviate-ts-client/node_modules/graphql-request/build/cjs/index.js:314:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  response: {
    errors: [
      {
        locations: [ { column: 14, line: 1 } ],
        message: 'Unknown argument "nearText" on field "Article" of type "GetObjectsObj". Did you mean "nearVector" or "nearObject"?',
        path: null
      }
    ]
     status: 200,
   ****
      }
    }
  },
  request: {
    query: '{Get{Article(nearText:{concepts:["sun","tree"]},limit:2){functional fictional}}}',
    variables: undefined
  }
}

Unable to add weaviate-ts-client to new React app

I am trying to install the ts client into a brand new React app. I followed these steps:

npx create-react-app react-app
cd react-app
npm install weaviate-ts-client
npm start

And I get a bunch of 'Module not found' errors.

npm was able to figure out some of the missing dependencies:

warning "weaviate-ts-client > [email protected]" has unmet peer dependency "graphql@14 - 16".
warning "weaviate-ts-client > graphql-request > @graphql-typed-document-node/[email protected]" has unmet peer dependency "graphql@^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0".

But even after adding those I get these errors when running npm start.

Module not found: Error: Can't resolve 'buffer' in '/Users/LGoolsby/dev/playground/searchv2/react-app/node_modules/safe-buffer'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
	- add a fallback 'resolve.fallback: { "buffer": require.resolve("buffer/") }'
	- install 'buffer'
If you don't want to include a polyfill, you can use an empty module like this:
	resolve.fallback: { "buffer": false }
WARNING in [eslint] 
src/App.js
  Line 1:8:  'logo' is defined but never used  no-unused-vars

ERROR in ./node_modules/safe-buffer/index.js 3:13-30
Module not found: Error: Can't resolve 'buffer' in '/Users/LGoolsby/dev/playground/searchv2/react-app/node_modules/safe-buffer'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
	- add a fallback 'resolve.fallback: { "buffer": require.resolve("buffer/") }'
	- install 'buffer'
If you don't want to include a polyfill, you can use an empty module like this:
	resolve.fallback: { "buffer": false }

ERROR in ./node_modules/weaviate-ts-client/dist/index.js 46:9-26
Module not found: Error: Can't resolve 'stream' in '/Users/LGoolsby/dev/playground/searchv2/react-app/node_modules/weaviate-ts-client/dist'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
	- add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
	- install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
	resolve.fallback: { "stream": false }

ERROR in ./node_modules/weaviate-ts-client/dist/index.js 356:11-36
Module not found: Error: Can't resolve 'zlib' in '/Users/LGoolsby/dev/playground/searchv2/react-app/node_modules/weaviate-ts-client/dist'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
	- add a fallback 'resolve.fallback: { "zlib": require.resolve("browserify-zlib") }'
	- install 'browserify-zlib'
If you don't want to include a polyfill, you can use an empty module like this:
	resolve.fallback: { "zlib": false }

ERROR in ./node_modules/weaviate-ts-client/dist/index.js 750:11-28
Module not found: Error: Can't resolve 'assert' in '/Users/LGoolsby/dev/playground/searchv2/react-app/node_modules/weaviate-ts-client/dist'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
	- add a fallback 'resolve.fallback: { "assert": require.resolve("assert/") }'
	- install 'assert'
If you don't want to include a polyfill, you can use an empty module like this:
	resolve.fallback: { "assert": false }

ERROR in ./node_modules/weaviate-ts-client/dist/index.js 751:9-33
Module not found: Error: Can't resolve 'buffer' in '/Users/LGoolsby/dev/playground/searchv2/react-app/node_modules/weaviate-ts-client/dist'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
	- add a fallback 'resolve.fallback: { "buffer": require.resolve("buffer/") }'
	- install 'buffer'
If you don't want to include a polyfill, you can use an empty module like this:
	resolve.fallback: { "buffer": false }

ERROR in ./node_modules/weaviate-ts-client/dist/index.js 1034:9-30
Module not found: Error: Can't resolve 'path' in '/Users/LGoolsby/dev/playground/searchv2/react-app/node_modules/weaviate-ts-client/dist'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
	- add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
	- install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
	resolve.fallback: { "path": false }

ERROR in ./node_modules/weaviate-ts-client/dist/index.js 1235:9-22
Module not found: Error: Can't resolve 'fs' in '/Users/LGoolsby/dev/playground/searchv2/react-app/node_modules/weaviate-ts-client/dist'

ERROR in ./node_modules/weaviate-ts-client/dist/index.js 2391:8-26
Module not found: Error: Can't resolve 'process' in '/Users/LGoolsby/dev/playground/searchv2/react-app/node_modules/weaviate-ts-client/dist'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
	- add a fallback 'resolve.fallback: { "process": require.resolve("process/browser") }'
	- install 'process'
If you don't want to include a polyfill, you can use an empty module like this:
	resolve.fallback: { "process": false }

ERROR in ./node_modules/weaviate-ts-client/dist/index.js 2873:8-23
Module not found: Error: Can't resolve 'util' in '/Users/LGoolsby/dev/playground/searchv2/react-app/node_modules/weaviate-ts-client/dist'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
	- add a fallback 'resolve.fallback: { "util": require.resolve("util/") }'
	- install 'util'
If you don't want to include a polyfill, you can use an empty module like this:
	resolve.fallback: { "util": false }

ERROR in ./node_modules/weaviate-ts-client/dist/index.js 3398:9-26
Module not found: Error: Can't resolve 'crypto' in '/Users/LGoolsby/dev/playground/searchv2/react-app/node_modules/weaviate-ts-client/dist'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
	- add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
	- install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
	resolve.fallback: { "crypto": false }

ERROR in ./node_modules/weaviate-ts-client/dist/index.js 5955:7-23
Module not found: Error: Can't resolve 'https' in '/Users/LGoolsby/dev/playground/searchv2/react-app/node_modules/weaviate-ts-client/dist'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
	- add a fallback 'resolve.fallback: { "https": require.resolve("https-browserify") }'
	- install 'https-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
	resolve.fallback: { "https": false }

ERROR in ./node_modules/weaviate-ts-client/dist/index.js 5956:10-24
Module not found: Error: Can't resolve 'net' in '/Users/LGoolsby/dev/playground/searchv2/react-app/node_modules/weaviate-ts-client/dist'

ERROR in ./node_modules/weaviate-ts-client/dist/index.js 5957:7-31
Module not found: Error: Can't resolve 'child_process' in '/Users/LGoolsby/dev/playground/searchv2/react-app/node_modules/weaviate-ts-client/dist'

ERROR in ./node_modules/weaviate-ts-client/dist/index.js 5958:7-28
Module not found: Error: Can't resolve 'path/posix' in '/Users/LGoolsby/dev/playground/searchv2/react-app/node_modules/weaviate-ts-client/dist'

ERROR in ./node_modules/weaviate-ts-client/dist/index.js 5959:7-20
Module not found: Error: Can't resolve 'os' in '/Users/LGoolsby/dev/playground/searchv2/react-app/node_modules/weaviate-ts-client/dist'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
	- add a fallback 'resolve.fallback: { "os": require.resolve("os-browserify/browser") }'
	- install 'os-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
	resolve.fallback: { "os": false }

webpack compiled with 15 errors and 1 warning

I'm assuming some additional packages are needed other than the weaviate client and graphql, but which ones isn't very clear. Anyone know how to get around this?

GraphQL Get: Query all properties if none are given

Currently get queries require to list all properties that should be returned and if no properties are given, the query returns an error.

Instead of returning an error, the client should get all non-reference properties from the schema if no properties are set and include those by default in the query.

Add support for generative openai module

Using the generative module is currently possible, but he UX is not that great. Its usage could be improved by adding a explicit support for this kind of query:

Note:

  • The module generative-openai needs to be enabled using ENABLE_MODULES=generative-openai
  • You need an openai API key:OPENAI_APIKEY=some_key
  • The tests should be skipped if no openai key is available
    For inspiration, check the python or go implementation

Can't work with Edge Runtime

When I try to use the typescript-client with the Edge Runtime API in Next.js, I get the error XMLHttpRequest is not defined.

The reason is that the default fetch for graphql-request is cross-fetch, and cross-fetch is not supported by Edge Runtime. (lquixada/cross-fetch#142)

I have forked this repository and verified that it works with Edge Runtime by modifying the following. (My environment is Node.js 18)

https://github.com/cm-igarashi-ryosuke/typescript-client/pull/1/files

However, I am not familiar with the need for cross-fetch and there may be side effects.

I created this issue because I think some people may have trouble with the same event in the future.

Please let me know if you have a good solution.

weaviate withNearImage never hits

So I have been trying for awhile now and I can't seem to get weaviate to hit any image when i use withNearImage .

When I remove withNearImage it will give me a image back and writing it to the disk is the same as when i was inputting. Data isn't getting lost.

Lastly when I reuse the same image I just get back when I run without withNearImage it still won't hit. Not sure what is wrong with my test script.

import { readFileSync, writeFileSync } from "fs";
import weaviate from 'weaviate-ts-client';

const test = Buffer.from(readFileSync(__dirname + '/test.jpg')).toString('base64');
writeFileSync(__dirname + '/test_out.jpg', Buffer.from(test, 'base64'));

console.log(test.length);

const weaviateClient = weaviate.client({
    scheme: 'http',
    host: process.env.WEAVIATE_HOST || 'localhost',
});

const run = async () => {
    try {
        const resImage = await weaviateClient.graphql.get()
        .withClassName('ImageSearch')
        .withFields('image')
        .withNearImage({image: test})
        .withLimit(1)
        .do();

        console.log(resImage.data.Get['ImageSearch'][0]);

        const result = resImage.data.Get['ImageSearch'][0].image;
        writeFileSync(__dirname + '/result.jpg', Buffer.from(result, 'base64'));
    } catch (e) {
        console.error(e);
        process.exit(1);
    }
}

run();

here is my error I get back when i run my script

yarn run v1.22.19
warning package.json: No license field
$ /app/node_modules/.bin/ts-node-dev src/test.ts
[INFO] 14:22:47 ts-node-dev ver. 2.0.0 (using ts-node ver. 10.9.1, typescript ver. 5.0.4)
121232
TypeError: Cannot read properties of undefined (reading 'image')
    at /app/src/test.ts:26:71
    at Generator.next (<anonymous>)
    at fulfilled (/app/src/test.ts:5:58)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Add method to check if a class exists

Add a function that returns if a given class exists in the schema

Proposal signature (copied from python as I don't know JS):
client.schema.exists(className: str) ->bool

Type definition of withProperties should be any, not any[]?

I've been using the javascript weaviate-client and just switched to this one. The migration was painless, and I only needed to make minor changes. One of them, however, surprised me. According to the JS documentation, withProperties requires an object (called schema in the example code from the website shown at the bottom). However, the TS documentation states it is a any[]. I prefer if it would be using generics, but shouldn't it be just any?

TypeScript type definition in updater.d.ts:

withProperties: (properties: any[]) => this;

JavaScript example from the website:

const weaviate = require('weaviate-client');

const client = weaviate.client({
  scheme: 'http',
  host: 'localhost:8080',
});

var className = 'Author';
var id = '36ddd591-2dee-4e7e-a3cc-eb86d30a4303';

client.data
    .getterById()
    .withClassName(className)
    .withId(id)
    .do()
    .then(res => {
        // alter the schema
        const schema = res.schema;
        schema.name = 'J. Kantor';
        return client.data
            .updater()
            .withId(id)
            .withClassName(thingClassName)
            .withProperties(schema)
            .withConsistencyLevel(weaviate.replication.ConsistencyLevel.ALL)  // default QUORUM
            .do();
        })
    .then(res => {
        console.log(res)
    })
    .catch(err => {
        console.error(err)
    });

Need explicit documentation for the JavaScript client methods

I'm trying to build a demo app using the JS client, and the documentation at https://weaviate.io/developers/weaviate/current/client-libraries/javascript.html barely scratches the surface. While it correctly directs the developer to the REST and GraphQL reference pages, it would be very helpful if it clarified the link between those and the builder pattern calling convention used by the client.

More specifically,

  • there's no mention of the .graphql member of the client. I only saw that in passing in this tutorial
  • the with... methods should be explicitly documented. A stop-gap measure would be to link to test files so the developer could see what with... methods are available.
  • client.graphql.raw() and .get() should be documented.

TypeScript definitions would've been another solution.

Connection fails when user-provided host URL contains the scheme

Connection fails when user-provided host URL contains the scheme

Issue:

When initializing the Weaviate Client, if a user provides a host URL that already contains a scheme (e.g., https), the connection fails. This is because both the host and scheme are concatenated in the code.

Expected Behavior:

The client should handle cases where the scheme might already exist in the provided host URL. The goal is consistent behavior in both Python and Typescript clients. For instance, a user should be able to use the same URL for both the Python and TypeScript clients without adjusting the URL format for each.

How to Reproduce:

# Python Example

client = weaviate.Client(url = "https://some-endpoint.weaviate.network")
// Works

const client: WeaviateClient = weaviate.client({
  scheme: 'https', host: 'some-endpoint.weaviate.network'
});
// Fails

const client: WeaviateClient = weaviate.client({
  scheme: 'https', host: 'https://some-endpoint.weaviate.network'
});

Warn when weaviate and/or client are outdated

Some users use very old versions of weaviate and client. We should warn them if it the minor version is 3 or more versions behind the last release.

Eg currently the last Weaviate version is 1.18.3, so we would warn users of 1.15 or below. We could do the same for the client versions.

How do I query object data using typescript client library with offset parameter?

env:
weaviate-ts-client:1.1.0

https://weaviate.io/developers/weaviate/api/rest/objects#paging-offset

According to the documentation, the Query Object interface supports paginated queries, but I can't find the relevant API

client.data
		.getter()
		.withOffset() // can not find offset api such like this
		.withClassName(schema)
		.withLimit(limit)
		.do()
		.then((res) => {
			console.log(res)
		})
		.catch((err) => {
			console.error(err)
		})

certainty parameter not found in The qna-openai module

https://weaviate.io/developers/weaviate/modules/reader-generator-modules/qna-openai

The qna-openai module tries to find an answer in the data objects of the specified class. If an answer is found within the given certainty range, it will be returned in the GraphQL _additional { answer { ... } } field. There will be a maximum of 1 answer returned, if this is above the optionally set certainty. The answer with the highest certainty (confidence level) will be returned.

  1. How can I use the certainty parameter to filter out irrelevant questions when using the question and answer module with OpenAI?
  2. And if certainty parameter is supported, is certainty:0.75 be properly when I want to return empty when users ask questions that are unrelated to the extracted article content?

Here is my code block

client.graphql
		.get()
		.withClassName(schema)
		.withAsk({
			question: question
		})
		.withFields(
			'content _additional { answer { hasAnswer property result startPosition endPosition } }'
		)
		.withLimit(1)
		.do()
		.then((res: any) => {
			console.log(JSON.stringify(res, null, 2))
			return res.data.Get[schema][0]._additional.answer.result
		})

Add support for properties in hybrid search

With 1.19.0 Weaviate supports properties in hybrid search: The BM25-part of hybrid only searches the given properties.

The properties should be added to the HybridBuilder and the resulting GraphQL query then needs to look like this:

hybrid:{query:\"hello\",  properties: ["prop1", "prop"] ...more options...}

The parameter is optional and not supplying it results in all properties being searched.

Example python PR

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.