Skip to content

Commit

Permalink
Upgrade pinecone-ts-client to v1.1.0 (langchain-ai#2648)
Browse files Browse the repository at this point in the history
* Begin cutover to new method sigs - Pinecone 0.1.6

* Import VectorOperationsApi from @pinecone-database

* Upgrade Pinecone vectorstore to use Pinecone SDK v1.0.0

* Upgrade Pinecone integration to v1.0.1

* Upgrade to pinecone v1.0.1 for latest fixes

* Commit yarn.lock

* Fix side effects by moving process.env reads into constructor

* Update langchain package.json and package.lock

* Update Pinecone to v1.1.0 and latest usage patterns

* Pass Pinecone client into PineconeStore

* Fix lint warning about import order

* Create a test Pinecone index with a stable name beforeEach test
-waitUntilReady ensures the index is available
-suppressConflicts will not throw errors if the index already exists

* Fix delete by IDs test by remove extraneous array

* Remove pnpm-lock.yaml from .gitignore

* Update preferred Pinecone client instantiation in docs

* Update Pinecone self query example with preferred client pattern

* Fix tests, lint, format

* Fix lint

* Fix format

* Remove index create/destroy from int tests for consistency

---------

Co-authored-by: jacoblee93 <[email protected]>
  • Loading branch information
zackproser and jacoblee93 authored Oct 4, 2023
1 parent 005707e commit cdbc942
Show file tree
Hide file tree
Showing 10 changed files with 619 additions and 561 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,4 @@ Chinook_Sqlite.sql

firebase-debug.log
firestore-debug.log

tmp/
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@ npm install -S dotenv @pinecone-database/pinecone
## Index docs

```typescript
import { PineconeClient } from "@pinecone-database/pinecone";
import { Pinecone } from "@pinecone-database/pinecone";
import * as dotenv from "dotenv";
import { Document } from "langchain/document";
import { OpenAIEmbeddings } from "langchain/embeddings/openai";
import { PineconeStore } from "langchain/vectorstores/pinecone";

dotenv.config();

const client = new PineconeClient();
await client.init({
apiKey: process.env.PINECONE_API_KEY,
environment: process.env.PINECONE_ENVIRONMENT,
});
const pineconeIndex = client.Index(process.env.PINECONE_INDEX);
// Instantiate a new Pinecone client, which will automatically read the
// env vars: PINECONE_API_KEY and PINECONE_ENVIRONMENT which come from
// the Pinecone dashboard at https://app.pinecone.io

const pinecone = new Pinecone();

const pineconeIndex = pinecone.Index(process.env.PINECONE_INDEX);

const docs = [
new Document({
Expand Down Expand Up @@ -60,7 +61,7 @@ await PineconeStore.fromDocuments(docs, new OpenAIEmbeddings(), {
## Query docs

```typescript
import { PineconeClient } from "@pinecone-database/pinecone";
import { Pinecone } from "@pinecone-database/pinecone";
import * as dotenv from "dotenv";
import { VectorDBQAChain } from "langchain/chains";
import { OpenAIEmbeddings } from "langchain/embeddings/openai";
Expand All @@ -69,12 +70,14 @@ import { PineconeStore } from "langchain/vectorstores/pinecone";

dotenv.config();

const client = new PineconeClient();
await client.init({
apiKey: process.env.PINECONE_API_KEY,
environment: process.env.PINECONE_ENVIRONMENT,
});
const pineconeIndex = client.Index(process.env.PINECONE_INDEX);

// Instantiate a new Pinecone client, which will automatically read the
// env vars: PINECONE_API_KEY and PINECONE_ENVIRONMENT which come from
// the Pinecone dashboard at https://app.pinecone.io

const pinecone = new Pinecone();

const pineconeIndex = pinecone.Index(process.env.PINECONE_INDEX);

const vectorStore = await PineconeStore.fromExistingIndex(
new OpenAIEmbeddings(),
Expand Down Expand Up @@ -119,20 +122,21 @@ console.log(response);
## Delete docs

```typescript
import { PineconeClient } from "@pinecone-database/pinecone";
import { Pinecone } from "@pinecone-database/pinecone";
import * as dotenv from "dotenv";
import { Document } from "langchain/document";
import { OpenAIEmbeddings } from "langchain/embeddings/openai";
import { PineconeStore } from "langchain/vectorstores/pinecone";

dotenv.config();

const client = new PineconeClient();
await client.init({
apiKey: process.env.PINECONE_API_KEY,
environment: process.env.PINECONE_ENVIRONMENT,
});
const pineconeIndex = client.Index(process.env.PINECONE_INDEX);
// Instantiate a new Pinecone client, which will automatically read the
// env vars: PINECONE_API_KEY and PINECONE_ENVIRONMENT which come from
// the Pinecone dashboard at https://app.pinecone.io

const pinecone = new Pinecone();

const pineconeIndex = pinecone.Index(process.env.PINECONE_INDEX);
const embeddings = new OpenAIEmbeddings();
const pineconeStore = new PineconeStore(embeddings, { pineconeIndex });

Expand Down
10 changes: 3 additions & 7 deletions examples/src/indexes/vector_stores/pinecone.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PineconeClient } from "@pinecone-database/pinecone";
import { Pinecone } from "@pinecone-database/pinecone";
import { OpenAIEmbeddings } from "langchain/embeddings/openai";
import { PineconeStore } from "langchain/vectorstores/pinecone";

Expand All @@ -18,12 +18,8 @@ export const run = async () => {
);
}

const client = new PineconeClient();
await client.init({
apiKey: process.env.PINECONE_API_KEY,
environment: process.env.PINECONE_ENVIRONMENT,
});
const index = client.Index(process.env.PINECONE_INDEX);
const pinecone = new Pinecone();
const index = pinecone.Index(process.env.PINECONE_INDEX);

const vectorStore = await PineconeStore.fromTexts(
["Hello world", "Bye bye", "hello nice world"],
Expand Down
12 changes: 4 additions & 8 deletions examples/src/retrievers/pinecone_self_query.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { PineconeClient } from "@pinecone-database/pinecone";

import { Pinecone } from "@pinecone-database/pinecone";
import { AttributeInfo } from "langchain/schema/query_constructor";
import { Document } from "langchain/document";
import { OpenAIEmbeddings } from "langchain/embeddings/openai";
Expand Down Expand Up @@ -96,12 +95,9 @@ if (
);
}

const client = new PineconeClient();
await client.init({
apiKey: process.env.PINECONE_API_KEY,
environment: process.env.PINECONE_ENVIRONMENT,
});
const index = client.Index(process.env.PINECONE_INDEX);
const pinecone = new Pinecone();

const index = pinecone.Index(process.env.PINECONE_INDEX);

const embeddings = new OpenAIEmbeddings();
const llm = new OpenAI();
Expand Down
4 changes: 2 additions & 2 deletions langchain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@
"@mozilla/readability": "^0.4.4",
"@notionhq/client": "^2.2.10",
"@opensearch-project/opensearch": "^2.2.0",
"@pinecone-database/pinecone": "^0.0.14",
"@pinecone-database/pinecone": "^1.1.0",
"@planetscale/database": "^1.8.0",
"@qdrant/js-client-rest": "^1.2.0",
"@raycast/api": "^1.55.2",
Expand Down Expand Up @@ -820,7 +820,7 @@
"@mozilla/readability": "*",
"@notionhq/client": "^2.2.10",
"@opensearch-project/opensearch": "*",
"@pinecone-database/pinecone": "*",
"@pinecone-database/pinecone": "^1.1.0",
"@planetscale/database": "^1.8.0",
"@qdrant/js-client-rest": "^1.2.0",
"@raycast/api": "^1.55.2",
Expand Down
Loading

0 comments on commit cdbc942

Please sign in to comment.