Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions components/weaviate/actions/create-class/create-class.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import app from "../../weaviate.app.mjs";

export default {
key: "weaviate-create-class",
name: "Create Class",
description: "Create a new class in Weaviate. [See the documentation](https://docs.weaviate.io/weaviate/api/rest#tag/schema/post/schema)",
version: "0.0.1",
type: "action",
props: {
app,
className: {
propDefinition: [
app,
"className",
],
},
properties: {
propDefinition: [
app,
"properties",
],
},
description: {
propDefinition: [
app,
"description",
],
},
multiTenancyEnabled: {
propDefinition: [
app,
"multiTenancyEnabled",
],
},
vectorIndexType: {
propDefinition: [
app,
"vectorIndexType",
],
},
},
async run({ $ }) {
const parsedProperties = this.properties?.map((p) => JSON.parse(p)) || [];
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Harden properties parsing to avoid unhandled JSON.parse errors and accept objects.

Invalid JSON will currently throw and fail the step; also breaks if an element is already an object.

-    const parsedProperties = this.properties?.map((p) => JSON.parse(p)) || [];
+    const parsedProperties = Array.isArray(this.properties)
+      ? this.properties.map((p, i) => {
+          if (typeof p === "string") {
+            try { return JSON.parse(p); }
+            catch (e) { throw new Error(`Invalid JSON in "properties"[${i}]: ${e.message}`); }
+          }
+          return p;
+        }).filter(Boolean)
+      : [];
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const parsedProperties = this.properties?.map((p) => JSON.parse(p)) || [];
const parsedProperties = Array.isArray(this.properties)
? this.properties.map((p, i) => {
if (typeof p === "string") {
try { return JSON.parse(p); }
catch (e) { throw new Error(`Invalid JSON in "properties"[${i}]: ${e.message}`); }
}
return p;
}).filter(Boolean)
: [];
🤖 Prompt for AI Agents
In components/weaviate/actions/create-class/create-class.mjs around line 43,
parsing of this.properties assumes every element is a JSON string and uses
JSON.parse directly, which throws on invalid JSON and fails for elements already
objects; change the mapping to handle three cases: if the element is
undefined/null skip it, if it's a string attempt JSON.parse inside a try/catch
and skip or log/collect only successfully parsed values, and if it's already an
object use it as-is; ensure the overall result defaults to an empty array when
this.properties is falsy and avoid throwing by catching parse errors and not
propagating them.

const response = await this.app.createClass({
$,
data: {
class: this.className,
description: this.description,
vectorizer: this.vectorizer,
multiTenancyConfig: {
enabled: this.multiTenancyEnabled,
},
vectorIndexType: this.vectorIndexType,
properties: parsedProperties,
},
});
$.export("$summary", "Successfully sent the request to create a new class");
return response;
},
};
26 changes: 26 additions & 0 deletions components/weaviate/actions/delete-class/delete-class.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import app from "../../weaviate.app.mjs";

export default {
key: "weaviate-delete-class",
name: "Delete Class",
description: "Delete a class from Weaviate. [See the documentation](https://docs.weaviate.io/weaviate/api/rest#tag/schema/delete/schema/{className})",
version: "0.0.1",
type: "action",
props: {
app,
classId: {
propDefinition: [
app,
"classId",
],
},
},
async run({ $ }) {
const response = await this.app.deleteClass({
$,
classId: this.classId,
});
$.export("$summary", "Successfully deleted the class named " + this.classId);
return response;
},
};
19 changes: 19 additions & 0 deletions components/weaviate/actions/get-schema/get-schema.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import app from "../../weaviate.app.mjs";

export default {
key: "weaviate-get-schema",
name: "Get Schema",
description: "Get schema from Weaviate. [See the documentation](https://docs.weaviate.io/weaviate/api/rest#tag/schema/get/schema)",
version: "0.0.1",
type: "action",
props: {
app,
},
async run({ $ }) {
const response = await this.app.getSchema({
$,
});
$.export("$summary", "Successfully retrieved the current database schema");
return response;
},
};
6 changes: 6 additions & 0 deletions components/weaviate/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
VECTOR_TYPES: [
"hnsw",
"flat",
],
};
Comment on lines +1 to +6
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

🧩 Analysis chain

Consider verifying if the vector types list is complete.

The constants module correctly exports the vector types. However, ensure these are all the supported vector index types in Weaviate.


🌐 Web query:

What are all the supported vector index types in Weaviate?

💡 Result:

Weaviate supports three vector index types: hnsw, flat, and dynamic. (docs.weaviate.io)

Citations:


Include 'dynamic' in VECTOR_TYPES export.

Weaviate supports "hnsw", "flat", and "dynamic" — update components/weaviate/common/constants.mjs (lines 1–6) to add "dynamic" to VECTOR_TYPES.

🤖 Prompt for AI Agents
In components/weaviate/common/constants.mjs around lines 1 to 6, the exported
VECTOR_TYPES array is missing the "dynamic" type; update the VECTOR_TYPES array
to include "dynamic" alongside "hnsw" and "flat" so it reads with the three
supported values ("hnsw", "flat", "dynamic"), and keep the export shape
unchanged.

5 changes: 4 additions & 1 deletion components/weaviate/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/weaviate",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Weaviate Components",
"main": "weaviate.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.1.0"
}
}
92 changes: 87 additions & 5 deletions components/weaviate/weaviate.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,93 @@
import { axios } from "@pipedream/platform";
import constants from "./common/constants.mjs";

export default {
type: "app",
app: "weaviate",
propDefinitions: {},
propDefinitions: {
className: {
type: "string",
label: "Class Name",
description: "The name of the class to create",
},
properties: {
type: "string[]",
label: "Properties",
description: "The properties of the class. Each item must be a JSON object string, e.g.: `{ \"name\": \"title\", \"dataType\": [\"text\"], \"description\": \"Title of the object\" }`",
},
description: {
type: "string",
label: "Description",
description: "Optional description of the class",
optional: true,
},
multiTenancyEnabled: {
type: "boolean",
label: "Multi-tenancy Enabled",
description: "Set to `true` to enable multi-tenancy for this class",
optional: true,
},
vectorIndexType: {
type: "string",
label: "Vector Index Type",
description: "Type of vector index to use",
optional: true,
options: constants.VECTOR_TYPES,
},
classId: {
type: "string",
label: "Class Name",
description: "Name of the Class",
async options() {
const response = await this.getSchema();
return response.classes.map(({ class: className }) => ({
value: className,
label: className,
}));
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return `https://${this.$auth.cluster_url}`;
},
async _makeRequest(opts = {}) {
const {
$ = this,
path,
headers,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: this._baseUrl() + path,
headers: {
Authorization: `Bearer ${this.$auth.api_key}`,
...headers,
},
});
},
async createClass(args = {}) {
return this._makeRequest({
path: "/v1/schema",
method: "post",
...args,
});
},
async deleteClass({
classId, ...args
}) {
return this._makeRequest({
path: `/v1/schema/${classId}`,
method: "delete",
...args,
});
},
async getSchema(args = {}) {
return this._makeRequest({
path: "/v1/schema",
...args,
});
},
},
};
};
15 changes: 8 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading