From 848a9022df832b4595473f8bae4b3a66564f0bda Mon Sep 17 00:00:00 2001 From: Tristen Harr Date: Mon, 25 Mar 2024 20:16:09 -0500 Subject: [PATCH] update to add support for recommend with uuid IDs --- CHANGELOG.md | 3 + connector-definition/connector-metadata.yaml | 4 +- package-lock.json | 4 +- package.json | 2 +- src/constants.ts | 230 ++++--------------- src/handlers/schema.ts | 5 +- 6 files changed, 50 insertions(+), 198 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ae8cd6..5b543ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ This changelog documents changes between release tags. ## [Unreleased] Upcoming changes for the next versioned release. +## [0.1.7] - 2024-03-25 +* Add handling for recommend with UUID's + ## [0.1.6] - 2024-03-22 * Fix error handling * Allow String (UUID) OR Integer IDs by introspecting the ID type. diff --git a/connector-definition/connector-metadata.yaml b/connector-definition/connector-metadata.yaml index 3706032..c40ef15 100644 --- a/connector-definition/connector-metadata.yaml +++ b/connector-definition/connector-metadata.yaml @@ -1,13 +1,13 @@ packagingDefinition: type: PrebuiltDockerImage - dockerImage: ghcr.io/hasura/ndc-qdrant:v0.1.6 + dockerImage: ghcr.io/hasura/ndc-qdrant:v0.1.7 supportedEnvironmentVariables: - name: QDRANT_URL description: The url for the Qdrant database - name: QDRANT_API_KEY description: The Qdrant API Key commands: - update: docker run --rm -e QDRANT_URL="$QDRANT_URL" -e QDRANT_API_KEY="$QDRANT_API_KEY" -v "$HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH":/etc/connector ghcr.io/hasura/ndc-qdrant:v0.1.6 update + update: docker run --rm -e QDRANT_URL="$QDRANT_URL" -e QDRANT_API_KEY="$QDRANT_API_KEY" -v "$HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH":/etc/connector ghcr.io/hasura/ndc-qdrant:v0.1.7 update dockerComposeWatch: - path: ./ target: /etc/connector diff --git a/package-lock.json b/package-lock.json index 74782a1..be1349a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ndc-qdrant", - "version": "0.1.6", + "version": "0.1.7", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "ndc-qdrant", - "version": "0.1.6", + "version": "0.1.7", "dependencies": { "@hasura/ndc-sdk-typescript": "^4.2.1", "@json-schema-tools/meta-schema": "^1.7.0", diff --git a/package.json b/package.json index 4d66bcc..6eb63b2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ndc-qdrant", - "version": "0.1.6", + "version": "0.1.7", "main": "index.js", "scripts": {}, "dependencies": { diff --git a/src/constants.ts b/src/constants.ts index 7dfd253..527847b 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -4,7 +4,6 @@ import { ObjectField, ObjectType, } from "@hasura/ndc-sdk-typescript"; -import { JSONSchemaObject } from "@json-schema-tools/meta-schema"; const ID_FIELD_TYPE: "Int" | "String" = "Int"; export const CAPABILITIES_RESPONSE: CapabilitiesResponse = { version: "^0.1.0", @@ -269,7 +268,7 @@ export const BASE_TYPES: { [k: string]: ObjectType } = { }, }, }, - _recommend: { + _recommendInt: { description: "Provide an array of positive and negative example points and get a recommendation", fields: { @@ -314,207 +313,60 @@ export const BASE_TYPES: { [k: string]: ObjectType } = { }, }, }, -}; - -// export const BASE_TYPES: { [k: string]: ObjectType } = {}; - -export const RESTRICTED_NAMES: string[] = ["id", "score", "vector", "version"]; -export const RESTRICTED_OBJECTS: string[] = [ - "_search", - "_recommend", - "_params", - "_quantization", -]; -export const MAX_32_INT: number = 2147483647; -export const RAW_CONFIGURATION_SCHEMA: JSONSchemaObject = { - $schema: "http://json-schema.org/draft-07/schema#", - definitions: { - ArgumentInfo: { - properties: { - description: { - description: "Argument description", - type: "string", - }, + _recommendString: { + description: + "Provide an array of positive and negative example points and get a recommendation", + fields: { + positive: { type: { - $ref: "#/definitions/Type", - description: "The name of the type of this argument", - }, - }, - type: "object", - }, - ConfigurationSchema: { - properties: { - collection_names: { - items: { - type: "string", - }, - type: "array", - }, - functions: { - items: { - $ref: "#/definitions/FunctionInfo", - }, type: "array", - }, - object_fields: { - additionalProperties: { - items: { - type: "string", - }, - type: "array", - }, - type: "object", - }, - object_types: { - additionalProperties: { - $ref: "#/definitions/ObjectType", - }, - type: "object", - }, - procedures: { - items: { - $ref: "#/definitions/ProcedureInfo", + element_type: { + type: "named", + name: "String", }, - type: "array", }, }, - type: "object", - }, - FunctionInfo: { - properties: { - arguments: { - additionalProperties: { - $ref: "#/definitions/ArgumentInfo", + negative: { + type: { + type: "nullable", + underlying_type: { + type: "array", + element_type: { + type: "named", + name: "String", + }, }, - description: "Any arguments that this collection requires", - type: "object", - }, - description: { - description: "Description of the function", - type: "string", - }, - name: { - description: "The name of the function", - type: "string", - }, - result_type: { - $ref: "#/definitions/Type", - description: "The name of the function's result type", }, }, - type: "object", - }, - ObjectField: { - description: "The definition of an object field", - properties: { - description: { - description: "Description of this field", - type: "string", - }, + params: { type: { - $ref: "#/definitions/Type", - description: "The type of this field", - }, - }, - type: "object", - }, - ObjectType: { - description: "The definition of an object type", - properties: { - description: { - description: "Description of this type", - type: "string", - }, - fields: { - additionalProperties: { - $ref: "#/definitions/ObjectField", + type: "nullable", + underlying_type: { + type: "named", + name: "_params", }, - description: "Fields defined on this object type", - type: "object", }, }, - type: "object", - }, - ProcedureInfo: { - properties: { - arguments: { - additionalProperties: { - $ref: "#/definitions/ArgumentInfo", + score_threshold: { + type: { + type: "nullable", + underlying_type: { + type: "named", + name: "Float", }, - description: "Any arguments that this collection requires", - type: "object", - }, - description: { - description: "Column description", - type: "string", - }, - name: { - description: "The name of the procedure", - type: "string", - }, - result_type: { - $ref: "#/definitions/Type", - description: "The name of the result type", }, }, - type: "object", - }, - Type: { - anyOf: [ - { - properties: { - name: { - description: - "The name can refer to a primitive type or a scalar type", - type: "string", - }, - type: { - const: "named", - type: "string", - }, - }, - type: "object", - }, - { - properties: { - type: { - const: "nullable", - type: "string", - }, - underlying_type: { - $ref: "#/definitions/Type", - description: "The type of the non-null inhabitants of this type", - }, - }, - type: "object", - }, - { - properties: { - element_type: { - $ref: "#/definitions/Type", - description: "The type of the elements of the array", - }, - type: { - const: "array", - type: "string", - }, - }, - type: "object", - }, - ], - description: "Types track the valid representations of values as JSON", - }, - }, - properties: { - config: { - $ref: "#/definitions/ConfigurationSchema", - }, - qdrant_api_key: { - type: "string", - }, - qdrant_url: { - type: "string", }, - }, - type: "object", + } }; + +// export const BASE_TYPES: { [k: string]: ObjectType } = {}; + +export const RESTRICTED_NAMES: string[] = ["id", "score", "vector", "version"]; +export const RESTRICTED_OBJECTS: string[] = [ + "_search", + "_recommend", + "_params", + "_quantization", +]; +export const MAX_32_INT: number = 2147483647; diff --git a/src/handlers/schema.ts b/src/handlers/schema.ts index 588e089..cee30eb 100644 --- a/src/handlers/schema.ts +++ b/src/handlers/schema.ts @@ -8,9 +8,6 @@ export function doGetSchema(objectTypes: { [k: string]: ObjectType }, collection for (const cn of Object.keys(objectTypes)){ if (collectionNames.includes(cn)){ let ID_FIELD_TYPE = "Int"; - console.log("HERE"); - console.log(objectTypes[cn]); - console.log(objectTypes[cn].fields["id"]); if (objectTypes[cn].fields["id"]["type"]["type"] === "named"){ ID_FIELD_TYPE = (objectTypes[cn].fields["id"]["type"] as any)["name"]; } else { @@ -34,7 +31,7 @@ export function doGetSchema(objectTypes: { [k: string]: ObjectType }, collection type: "nullable", underlying_type: { type: "named", - name: "_recommend" + name: `_recommend${ID_FIELD_TYPE}` } } }