Skip to content

Implement Namespaces API - generate off of 2024-04 #340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 2025-04
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion codegen/apis
Submodule apis updated from bec629 to df8c28
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"build": "rm -rf dist/ && tsc",
"version": "jq --null-input --arg version $npm_package_version '{\"name\": \"@pinecone-database/pinecone\", \"version\": $version}' > src/version.json",
"docs:build": "typedoc --plugin ./assets/docs-theme.mjs",
"generate:openapi": "./codegen/build-oas.sh 2025-01 && npm run build && npm run format",
"generate:openapi": "./codegen/build-oas.sh 2025-04 && npm run build && npm run format",
"format": "prettier --write .",
"lint": "eslint src/ --ext .ts",
"repl": "npm run build && node utils/replInit.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/assistant/control/createAssistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import { PineconeArgumentError } from '../../errors';
export const createAssistant = (api: ManageAssistantsControlApi) => {
return async (options: CreateAssistantOptions): Promise<AssistantModel> => {
validateCreateAssistantOptions(options);
return await api.createAssistant({
return (await api.createAssistant({
createAssistantRequest: {
name: options.name,
instructions: options?.instructions,
metadata: options?.metadata,
region: options?.region as CreateAssistantRequestRegionEnum,
},
});
})) as AssistantModel;
};
};

Expand Down
4 changes: 2 additions & 2 deletions src/assistant/control/describeAssistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const describeAssistant = (api: ManageAssistantsControlApi) => {
'You must pass the name of an assistant to update.'
);
}
return await api.getAssistant({
return (await api.getAssistant({
assistantName: assistantName,
});
})) as AssistantModel;
};
};
2 changes: 1 addition & 1 deletion src/assistant/control/listAssistants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import type { AssistantList } from './types';

export const listAssistants = (api: ManageAssistantsControlApi) => {
return async (): Promise<AssistantList> => {
return await api.listAssistants();
return (await api.listAssistants()) as AssistantList;
};
};
33 changes: 33 additions & 0 deletions src/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ import { ListImportsCommand } from './bulk/listImports';
import { DescribeImportCommand } from './bulk/describeImport';
import { CancelImportCommand } from './bulk/cancelImport';
import { BulkOperationsProvider } from './bulk/bulkOperationsProvider';
import { NamespaceOperationsProvider } from './namespaces/namespacesOperationsProvider';
import { listNamespaces } from './namespaces/listNamespaces';
import { describeNamespace } from './namespaces/describeNamespace';
import { deleteNamespace } from './namespaces/deleteNamespace';

export type {
PineconeConfiguration,
Expand Down Expand Up @@ -167,6 +171,12 @@ export class Index<T extends RecordMetadata = RecordMetadata> {
private _describeImportCommand: DescribeImportCommand;
/** @hidden */
private _cancelImportCommand: CancelImportCommand;
/** @hidden */
private _listNamespacesCommand: ReturnType<typeof listNamespaces>;
/** @hidden */
private _describeNamespaceCommand: ReturnType<typeof describeNamespace>;
/** @hidden */
private _deleteNamespaceCommand: ReturnType<typeof deleteNamespace>;

/** @internal */
private config: PineconeConfiguration;
Expand Down Expand Up @@ -269,6 +279,17 @@ export class Index<T extends RecordMetadata = RecordMetadata> {
bulkApiProvider,
namespace
);

// namespace operations
const namespaceApiProvider = new NamespaceOperationsProvider(
config,
indexName,
indexHostUrl,
additionalHeaders
);
this._listNamespacesCommand = listNamespaces(namespaceApiProvider);
this._describeNamespaceCommand = describeNamespace(namespaceApiProvider);
this._deleteNamespaceCommand = deleteNamespace(namespaceApiProvider);
}

/**
Expand Down Expand Up @@ -798,4 +819,16 @@ export class Index<T extends RecordMetadata = RecordMetadata> {
async cancelImport(id: string) {
return await this._cancelImportCommand.run(id);
}

async listNamespaces() {
return await this._listNamespacesCommand();
}

async describeNamespace(namespace: string) {
return await this._describeNamespaceCommand(namespace);
}

async deleteNamespace(namespace: string) {
return await this._deleteNamespaceCommand(namespace);
}
}
9 changes: 9 additions & 0 deletions src/data/namespaces/deleteNamespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { NamespaceOperationsProvider } from '../namespaces/namespacesOperationsProvider';

export const deleteNamespace = (apiProvider: NamespaceOperationsProvider) => {
return async (namespace: string): Promise<void> => {
const api = await apiProvider.provide();
await api.deleteNamespace({ namespace });
return;
};
};
9 changes: 9 additions & 0 deletions src/data/namespaces/describeNamespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { NamespaceDescription } from '../../pinecone-generated-ts-fetch/db_data';
import { NamespaceOperationsProvider } from '../namespaces/namespacesOperationsProvider';

export const describeNamespace = (apiProvider: NamespaceOperationsProvider) => {
return async (namespace: string): Promise<NamespaceDescription> => {
const api = await apiProvider.provide();
return await api.describeNamespace({ namespace });
};
};
9 changes: 9 additions & 0 deletions src/data/namespaces/listNamespaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ListNamespacesResponse } from '../../pinecone-generated-ts-fetch/db_data';
import { NamespaceOperationsProvider } from '../namespaces/namespacesOperationsProvider';

export const listNamespaces = (apiProvider: NamespaceOperationsProvider) => {
return async (): Promise<ListNamespacesResponse> => {
const api = await apiProvider.provide();
return await api.listNamespaces();
};
};
77 changes: 77 additions & 0 deletions src/data/namespaces/namespacesOperationsProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import type { PineconeConfiguration } from '../vectors/types';
import type { HTTPHeaders } from '../../pinecone-generated-ts-fetch/db_data';
import {
Configuration,
ConfigurationParameters,
NamespaceOperationsApi,
X_PINECONE_API_VERSION,
} from '../../pinecone-generated-ts-fetch/db_data';
import {
buildUserAgent,
getFetch,
normalizeUrl,
queryParamsStringify,
} from '../../utils';
import { IndexHostSingleton } from '../indexHostSingleton';
import { middleware } from '../../utils/middleware';

export class NamespaceOperationsProvider {
private readonly config: PineconeConfiguration;
private readonly indexName: string;
private indexHostUrl?: string;
private namespaceOperations?: NamespaceOperationsApi;
private readonly additionalHeaders?: HTTPHeaders;

constructor(
config: PineconeConfiguration,
indexName: string,
indexHostUrl?: string,
additionalHeaders?: HTTPHeaders
) {
this.config = config;
this.indexName = indexName;
this.indexHostUrl = normalizeUrl(indexHostUrl);
this.additionalHeaders = additionalHeaders;
}

async provide() {
if (this.namespaceOperations) {
return this.namespaceOperations;
}

// If an indexHostUrl has been manually passed we use that,
// otherwise we rely on resolving the host from the IndexHostSingleton
if (this.indexHostUrl) {
this.namespaceOperations = this.buildNamespaceOperationsConfig();
} else {
this.indexHostUrl = await IndexHostSingleton.getHostUrl(
this.config,
this.indexName
);

this.namespaceOperations = this.buildNamespaceOperationsConfig();
}

return this.namespaceOperations;
}

buildNamespaceOperationsConfig() {
const headers = this.additionalHeaders || null;

const indexConfigurationParameters: ConfigurationParameters = {
basePath: this.indexHostUrl,
apiKey: this.config.apiKey,
queryParamsStringify,
headers: {
'User-Agent': buildUserAgent(this.config),
'X-Pinecone-Api-Version': X_PINECONE_API_VERSION,
...headers,
},
fetchApi: getFetch(this.config),
middleware,
};

const indexConfiguration = new Configuration(indexConfigurationParameters);
return new NamespaceOperationsApi(indexConfiguration);
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const X_PINECONE_API_VERSION = '2025-01';
export const X_PINECONE_API_VERSION = '2025-04';
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Pinecone Assistant Control Plane API
* Pinecone Assistant Engine is a context engine to store and retrieve relevant knowledge from millions of documents at scale. This API supports creating and managing assistants.
*
* The version of the OpenAPI document: 2025-01
* The version of the OpenAPI document: 2025-04
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Pinecone Assistant Control Plane API
* Pinecone Assistant Engine is a context engine to store and retrieve relevant knowledge from millions of documents at scale. This API supports creating and managing assistants.
*
* The version of the OpenAPI document: 2025-01
* The version of the OpenAPI document: 2025-04
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down Expand Up @@ -71,7 +71,8 @@ export const AssistantStatusEnum = {
Initializing: 'Initializing',
Failed: 'Failed',
Ready: 'Ready',
Terminating: 'Terminating'
Terminating: 'Terminating',
InitializationFailed: 'InitializationFailed'
} as const;
export type AssistantStatusEnum = typeof AssistantStatusEnum[keyof typeof AssistantStatusEnum];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Pinecone Assistant Control Plane API
* Pinecone Assistant Engine is a context engine to store and retrieve relevant knowledge from millions of documents at scale. This API supports creating and managing assistants.
*
* The version of the OpenAPI document: 2025-01
* The version of the OpenAPI document: 2025-04
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Pinecone Assistant Control Plane API
* Pinecone Assistant Engine is a context engine to store and retrieve relevant knowledge from millions of documents at scale. This API supports creating and managing assistants.
*
* The version of the OpenAPI document: 2025-01
* The version of the OpenAPI document: 2025-04
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Pinecone Assistant Control Plane API
* Pinecone Assistant Engine is a context engine to store and retrieve relevant knowledge from millions of documents at scale. This API supports creating and managing assistants.
*
* The version of the OpenAPI document: 2025-01
* The version of the OpenAPI document: 2025-04
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Pinecone Assistant Control Plane API
* Pinecone Assistant Engine is a context engine to store and retrieve relevant knowledge from millions of documents at scale. This API supports creating and managing assistants.
*
* The version of the OpenAPI document: 2025-01
* The version of the OpenAPI document: 2025-04
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Pinecone Assistant Control Plane API
* Pinecone Assistant Engine is a context engine to store and retrieve relevant knowledge from millions of documents at scale. This API supports creating and managing assistants.
*
* The version of the OpenAPI document: 2025-01
* The version of the OpenAPI document: 2025-04
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Pinecone Assistant Control Plane API
* Pinecone Assistant Engine is a context engine to store and retrieve relevant knowledge from millions of documents at scale. This API supports creating and managing assistants.
*
* The version of the OpenAPI document: 2025-01
* The version of the OpenAPI document: 2025-04
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Pinecone Assistant Control Plane API
* Pinecone Assistant Engine is a context engine to store and retrieve relevant knowledge from millions of documents at scale. This API supports creating and managing assistants.
*
* The version of the OpenAPI document: 2025-01
* The version of the OpenAPI document: 2025-04
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const X_PINECONE_API_VERSION = '2025-01';
export const X_PINECONE_API_VERSION = '2025-04';
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Pinecone Assistant Data Plane API
* Pinecone Assistant Engine is a context engine to store and retrieve relevant knowledge from millions of documents at scale. This API supports interactions with assistants.
*
* The version of the OpenAPI document: 2025-01
* The version of the OpenAPI document: 2025-04
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Pinecone Assistant Data Plane API
* Pinecone Assistant Engine is a context engine to store and retrieve relevant knowledge from millions of documents at scale. This API supports interactions with assistants.
*
* The version of the OpenAPI document: 2025-01
* The version of the OpenAPI document: 2025-04
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
16 changes: 15 additions & 1 deletion src/pinecone-generated-ts-fetch/assistant_data/models/Chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Pinecone Assistant Data Plane API
* Pinecone Assistant Engine is a context engine to store and retrieve relevant knowledge from millions of documents at scale. This API supports interactions with assistants.
*
* The version of the OpenAPI document: 2025-01
* The version of the OpenAPI document: 2025-04
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand All @@ -13,6 +13,12 @@
*/

import { exists, mapValues } from '../runtime';
import type { ContextOptionsModel } from './ContextOptionsModel';
import {
ContextOptionsModelFromJSON,
ContextOptionsModelFromJSONTyped,
ContextOptionsModelToJSON,
} from './ContextOptionsModel';
import type { MessageModel } from './MessageModel';
import {
MessageModelFromJSON,
Expand Down Expand Up @@ -62,6 +68,12 @@ export interface Chat {
* @memberof Chat
*/
includeHighlights?: boolean;
/**
*
* @type {ContextOptionsModel}
* @memberof Chat
*/
contextOptions?: ContextOptionsModel;
}


Expand Down Expand Up @@ -101,6 +113,7 @@ export function ChatFromJSONTyped(json: any, ignoreDiscriminator: boolean): Chat
'filter': !exists(json, 'filter') ? undefined : json['filter'],
'jsonResponse': !exists(json, 'json_response') ? undefined : json['json_response'],
'includeHighlights': !exists(json, 'include_highlights') ? undefined : json['include_highlights'],
'contextOptions': !exists(json, 'context_options') ? undefined : ContextOptionsModelFromJSON(json['context_options']),
};
}

Expand All @@ -119,6 +132,7 @@ export function ChatToJSON(value?: Chat | null): any {
'filter': value.filter,
'json_response': value.jsonResponse,
'include_highlights': value.includeHighlights,
'context_options': ContextOptionsModelToJSON(value.contextOptions),
};
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Pinecone Assistant Data Plane API
* Pinecone Assistant Engine is a context engine to store and retrieve relevant knowledge from millions of documents at scale. This API supports interactions with assistants.
*
* The version of the OpenAPI document: 2025-01
* The version of the OpenAPI document: 2025-04
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Pinecone Assistant Data Plane API
* Pinecone Assistant Engine is a context engine to store and retrieve relevant knowledge from millions of documents at scale. This API supports interactions with assistants.
*
* The version of the OpenAPI document: 2025-01
* The version of the OpenAPI document: 2025-04
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
Loading
Loading