Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@pinecone-database/pinecone-ts-client

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pinecone-database/pinecone-ts-client

This is the Typescript client for Pinecone. It is a wrapper around the Pinecone OpenAPI spec.

  • 0.0.1
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Pinecone Typescript Client

This is the Typescript client for Pinecone. It is a wrapper around the Pinecone OpenAPI spec.

Maintenance Npm package version

Installation

npm i @pinecone-database/pinecone-ts-client

Usage

Set the following environment variables:

PINECONE_API_KEY=your_api_key
PINECONE_ENVIRONMENT=your_environment

Initializing the client

import { PineconeClient } from "@pinecone-database/pinecone-ts-client";

// Create a client
const client = new PineconeClient();

// Initialize the client
await client.init({
  apiKey: process.env.PINECONE_API_KEY,
  environment: process.env.PINECONE_ENVIRONMENT,
});

Control plane operations

The Pinecone control plane allows you to perform the following operations:

  1. Create, configure and delete indexes
  2. Get information about an existing indexes
  3. Create and delete collections
  4. Select an index to operate on

Indexes

Create Index

const createRequest: CreateRequest = {
  name: indexName,
  dimension: dimensions,
  metric,
};

await client.createIndex(createRequest);

Delete Index

await client.deleteIndex(indexName);

Describe Index

const indexDescription = await client.describeIndex(indexName);

Example result:

{
  "database": {
    "name": "my-index",
    "metric": "cosine",
    "dimension": 10,
    "replicas": 1,
    "shards": 1,
    "pods": 1,
    "pod_type": "p1.x1"
  },
  "status": {
    "waiting": [],
    "crashed": [],
    "host": "my-index-[project-id].svc.[environment].pinecone.io",
    "port": 433,
    "state": "Ready",
    "ready": true
  }
}

List Indexes

const list = await client.listIndexes();

Example result:

["index1", "index2"]

Select an index

To operate on an index, you must select it. This is done by calling the Index method on the client.

const index = client.Index(indexName);

Collections

Create Collection

const createCollectionRequest: CreateCollectionRequest = {
  name: collection,
  source: indexName,
};
await client.createCollection(createCollectionRequest);

Delete Collection

await client.deleteCollection(collection);

Describe Collection

const describeCollection = await client.describeCollection(collection);

Example result:

{
  "name": "my-collection",
  "status": "Ready",
  "size": 3059815,
  "dimension": 10
}

List Collections

const list = await client.listCollections();

Example result:

["collection1", "collection2"]

Index operations

The Pinecone index operations allow you to perform the following operations instances of Vector.

A Vector is defined as follows:

type Vector = {
  id: string;
  values: number[];
  metadata?: object;
};

After selecting an index to operate on, you can:

Upsert vectors

const upsertRequest: UpsertRequest = {
  vectors,
  namespace,
};
await index.upsert(upsertRequest);

Query vectors

const vectors = [...] // array of vectors

const queryRequest: QueryRequest = {
  topK: 1,
  vector,
  namespace
}

const queryResponse = await index.query(queryRequest)

Update a vector

const updateRequest: UpdateRequest = {
  id: vectorId, // the ID of the vector to update
  values: [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0], // the new vector values
  setMetadata: metadata, // the new metadata
  namespace,
};
await index.update(updateRequest);

Fetch vectors by their IDs

const fetchResult = await index.fetch([vectorIDs], namespace);

Delete vectors

await index.delete1([vectorIDs], false, namespace);

Delete all vectors in a namespace

await index.delete1([], true, namespace);

FAQs

Package last updated on 20 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc