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
69 changes: 69 additions & 0 deletions components/needle/actions/search-collection/search-collection.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import app from "../../needle.app.mjs";

export default {
key: "needle-search-collection",
name: "Search Collection",
description: "Search a collection for relevant data chunks based on a query. [See the documentation](https://docs.needle-ai.com/docs/api-reference/search-collection/).",
version: "0.0.1",
type: "action",
props: {
app,
collectionId: {
propDefinition: [
app,
"collectionId",
],
},
text: {
type: "string",
label: "Search Query",
description: "The text to search for in the collection.",
},
maxDistance: {
type: "string",
label: "Maximum Similarity Distance",
description: "Maximum similarity distance for the search results, between `0` and `1`. Eg. `0.65`.",
optional: true,
},
topK: {
type: "integer",
label: "Maximum Number Of Results",
description: "The maximum number of search results to return.",
optional: true,
},
},
methods: {
searchCollection({
collectionId, ...args
} = {}) {
return this.app.post({
subdomain: "search.",
path: `/collections/${collectionId}/search`,
...args,
});
},
},
async run({ $ }) {
const {
searchCollection,
collectionId,
text,
maxDistance,
topK,
} = this;

const response = await searchCollection({
$,
collectionId,
data: {
text,
max_distance: maxDistance,
top_k: topK,
},
});

$.export("$summary", "Successfully searched the collection.");

return response;
},
};
9 changes: 9 additions & 0 deletions components/needle/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const SUBDOMAIN_PLACEHOLDER = "{subdomain}";
const BASE_URL = `https://${SUBDOMAIN_PLACEHOLDER}needle-ai.com`;
const VERSION_PATH = "/api/v1";

export default {
SUBDOMAIN_PLACEHOLDER,
BASE_URL,
VERSION_PATH,
};
61 changes: 56 additions & 5 deletions components/needle/needle.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,62 @@
import { axios } from "@pipedream/platform";
import constants from "./common/constants.mjs";

export default {
type: "app",
app: "needle",
propDefinitions: {},
propDefinitions: {
collectionId: {
type: "string",
label: "Collection ID",
description: "The ID of the collection to search in.",
async options() {
const { result: collections } = await this.listCollections();
return collections.map(({
id: value,
name: label,
}) => ({
label,
value,
}));
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
getUrl(path, subdomain = "") {
const baseUrl = constants.BASE_URL.replace(
constants.SUBDOMAIN_PLACEHOLDER,
subdomain,
);
return `${baseUrl}${constants.VERSION_PATH}${path}`;
},
getHeaders(headers) {
return {
"Content-Type": "application/json",
"Accept": "application/json",
"x-api-key": this.$auth.api_key,
...headers,
};
},
makeRequest({
$ = this, path, headers, subdomain, ...args
} = {}) {
return axios($, {
...args,
url: this.getUrl(path, subdomain),
headers: this.getHeaders(headers),
});
},
post(args) {
return this.makeRequest({
method: "POST",
...args,
});
},
listCollections(args = {}) {
return this.makeRequest({
path: "/collections",
...args,
});
},
},
};
};
7 changes: 5 additions & 2 deletions components/needle/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/needle",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Needle Components",
"main": "needle.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
}
6 changes: 5 additions & 1 deletion pnpm-lock.yaml

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

Loading