Skip to content

Commit

Permalink
fix(sdk-js): url option in search
Browse files Browse the repository at this point in the history
  • Loading branch information
louis030195 committed Jun 12, 2023
1 parent cb4f38f commit ccb530f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
29 changes: 13 additions & 16 deletions sdk/embedbase-js/src/EmbedbaseExperimentalClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
ClientSearchData,
ClientSearchResponse,
Document,
SearchOptions,
ExperimentalSearchOptions,
GenerateOptions,
Metadata,
RangeOptions,
Expand All @@ -31,7 +31,7 @@ class SearchBuilder implements PromiseLike<ClientSearchData> {
private client: EmbedbaseExperimentalClient,
private dataset: string,
private query: string,
private options: SearchOptions = {}
private options: ExperimentalSearchOptions = {}
) { }

/**
Expand All @@ -44,17 +44,14 @@ class SearchBuilder implements PromiseLike<ClientSearchData> {
*/
async search(): Promise<ClientSearchData> {
const top_k = this.options.limit || 5
let searchUrl = 'https://app.embedbase.xyz/api/search'
let searchUrl =
this.options.url ||
'https://app.embedbase.xyz/api/search'
let requestBody: any = {
query: this.query, top_k,
datasets_id: [this.dataset]
}

// HACK: temporary hack slowly switching from python fastapi to js api
if (searchUrl.includes("app.embedbase.xyz")) {
requestBody.datasets_id = [this.dataset]
}

if (this.options.where) {
requestBody.where = this.options.where;
}
Expand Down Expand Up @@ -266,7 +263,7 @@ export default class EmbedbaseExperimentalClient {
* Searches for most similar documents in a dataset using the search query and options provided.
*
* @param {string} query - The search query.
* @param {SearchOptions} options - Optional search options.
* @param {ExperimentalSearchOptions} options - Optional search options.
* @returns {SearchBuilder} - Returns a SearchBuilder instance to build search queries.
*
* @example
Expand All @@ -275,7 +272,7 @@ export default class EmbedbaseExperimentalClient {
search(
dataset: string,
query: string,
options: SearchOptions = {}
options: ExperimentalSearchOptions = {}
): SearchBuilder {
return new SearchBuilder(this, dataset, query, options);
}
Expand Down Expand Up @@ -402,13 +399,13 @@ export default class EmbedbaseExperimentalClient {
* Searches for most similar documents in a dataset using the search query and options provided.
*
* @param {string} query - The search query.
* @param {SearchOptions} options - Optional search options.
* @param {ExperimentalSearchOptions} options - Optional search options.
* @returns {SearchBuilder} - Returns a SearchBuilder instance to build search queries.
*
* @example
* const searchBuilder = embedbase.dataset('dataset_name').search('search_query');
*/
search: (query: string, options?: SearchOptions) => SearchBuilder
search: (query: string, options?: ExperimentalSearchOptions) => SearchBuilder
/**
* Adds a document to the dataset with optional metadata.
*
Expand All @@ -435,13 +432,13 @@ export default class EmbedbaseExperimentalClient {
* Creates a context based on the search query and options provided.
*
* @param {string} query - The search query.
* @param {SearchOptions} options - Optional search options.
* @param {ExperimentalSearchOptions} options - Optional search options.
* @returns {Promise<ClientContextData>} - Resolves to a ClientContextData object.
*
* @example
* const contextData = await embedbase.dataset('dataset_name').createContext('search_query');
*/
createContext: (query: string, options?: SearchOptions) => Promise<ClientContextData>
createContext: (query: string, options?: ExperimentalSearchOptions) => Promise<ClientContextData>
/**
*
* @param {string} dataset
Expand Down Expand Up @@ -553,11 +550,11 @@ export default class EmbedbaseExperimentalClient {

} {
return {
search: (query: string, options?: SearchOptions) =>
search: (query: string, options?: ExperimentalSearchOptions) =>
this.search(dataset, query, options),
add: async (document: string, metadata?: Metadata) => this.add(dataset, document, metadata),
batchAdd: async (documents: BatchAddDocument[]) => this.batchAdd(dataset, documents),
createContext: async (query: string, options?: SearchOptions) =>
createContext: async (query: string, options?: ExperimentalSearchOptions) =>
this.createContext(dataset, query, options),
list: (options?: RangeOptions) => this.list(dataset, options),
clear: async () => this.clear(dataset),
Expand Down
6 changes: 6 additions & 0 deletions sdk/embedbase-js/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ export interface SearchOptions {
where?: object
}

export interface ExperimentalSearchOptions {
limit?: number
where?: object
url?: string
}

export interface Document {
id: string
data: string
Expand Down

2 comments on commit ccb530f

@vercel
Copy link

@vercel vercel bot commented on ccb530f Jun 12, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on ccb530f Jun 12, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

embedbase – ./dashboard

embedbase.vercel.app
embedbase-git-main-prologe.vercel.app
embedbase-prologe.vercel.app
app.embedbase.xyz

Please sign in to comment.