Skip to content

Commit

Permalink
update to add support for recommend with uuid IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristen Harr authored and Tristen Harr committed Mar 26, 2024
1 parent 2e2de63 commit 848a902
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 198 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions connector-definition/connector-metadata.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ndc-qdrant",
"version": "0.1.6",
"version": "0.1.7",
"main": "index.js",
"scripts": {},
"dependencies": {
Expand Down
230 changes: 41 additions & 189 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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;
5 changes: 1 addition & 4 deletions src/handlers/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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}`
}
}
}
Expand Down

0 comments on commit 848a902

Please sign in to comment.