From 41b4cac0d84647f2aa20fa3fd895847a2799181b Mon Sep 17 00:00:00 2001 From: Sachin Chaurasiya Date: Tue, 23 Jul 2024 00:23:02 +0530 Subject: [PATCH 1/2] docs: Update PineconeStore creation to include namespace parameter --- docs/core_docs/docs/how_to/qa_per_user.ipynb | 12 +++++++++++- examples/src/indexes/vector_stores/pinecone/mmr.ts | 12 +++++++++++- .../src/indexes/vector_stores/pinecone/query_docs.ts | 12 +++++++++++- ...c_similarity_example_selector_custom_retriever.ts | 12 +++++++++++- 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/docs/core_docs/docs/how_to/qa_per_user.ipynb b/docs/core_docs/docs/how_to/qa_per_user.ipynb index b903c7797a9b..4e29ca6dd5b7 100644 --- a/docs/core_docs/docs/how_to/qa_per_user.ipynb +++ b/docs/core_docs/docs/how_to/qa_per_user.ipynb @@ -121,9 +121,19 @@ "\n", "const pineconeIndex = pinecone.Index(Deno.env.get(\"PINECONE_INDEX\"));\n", "\n", + "/**\n", + " * Pinecone allows you to partition the records in an index into namespaces. \n", + " * Queries and other operations are then limited to one namespace, \n", + " * so different requests can search different subsets of your index.\n", + " * Read more about namespaces here: https://docs.pinecone.io/guides/indexes/use-namespaces\n", + " * \n", + " * NOTE: If you have namespace enabled in your Pinecone index, you must provide the namespace when creating the PineconeStore.\n", + " */\n", + "const namespace = \"pinecone\";\n", + "\n", "const vectorStore = await PineconeStore.fromExistingIndex(\n", " new OpenAIEmbeddings(),\n", - " { pineconeIndex },\n", + " { pineconeIndex, namespace },\n", ");\n", "\n", "await vectorStore.addDocuments(\n", diff --git a/examples/src/indexes/vector_stores/pinecone/mmr.ts b/examples/src/indexes/vector_stores/pinecone/mmr.ts index 223ec3726377..779cee9f73ed 100644 --- a/examples/src/indexes/vector_stores/pinecone/mmr.ts +++ b/examples/src/indexes/vector_stores/pinecone/mmr.ts @@ -11,9 +11,19 @@ const pinecone = new Pinecone(); const pineconeIndex = pinecone.Index(process.env.PINECONE_INDEX!); +/** + * Pinecone allows you to partition the records in an index into namespaces. + * Queries and other operations are then limited to one namespace, + * so different requests can search different subsets of your index. + * Read more about namespaces here: https://docs.pinecone.io/guides/indexes/use-namespaces + * + * NOTE: If you have namespace enabled in your Pinecone index, you must provide the namespace when creating the PineconeStore. + */ +const namespace = "pinecone"; + const vectorStore = await PineconeStore.fromExistingIndex( new OpenAIEmbeddings(), - { pineconeIndex } + { pineconeIndex, namespace } ); /* Search the vector DB independently with meta filters */ diff --git a/examples/src/indexes/vector_stores/pinecone/query_docs.ts b/examples/src/indexes/vector_stores/pinecone/query_docs.ts index 72a8704d2449..ff32b366cb3f 100644 --- a/examples/src/indexes/vector_stores/pinecone/query_docs.ts +++ b/examples/src/indexes/vector_stores/pinecone/query_docs.ts @@ -11,9 +11,19 @@ const pinecone = new Pinecone(); const pineconeIndex = pinecone.Index(process.env.PINECONE_INDEX!); +/** + * Pinecone allows you to partition the records in an index into namespaces. + * Queries and other operations are then limited to one namespace, + * so different requests can search different subsets of your index. + * Read more about namespaces here: https://docs.pinecone.io/guides/indexes/use-namespaces + * + * NOTE: If you have namespace enabled in your Pinecone index, you must provide the namespace when creating the PineconeStore. + */ +const namespace = "pinecone"; + const vectorStore = await PineconeStore.fromExistingIndex( new OpenAIEmbeddings(), - { pineconeIndex } + { pineconeIndex, namespace } ); /* Search the vector DB independently with metadata filters */ diff --git a/examples/src/prompts/semantic_similarity_example_selector_custom_retriever.ts b/examples/src/prompts/semantic_similarity_example_selector_custom_retriever.ts index 980e2cbe6557..a96d0ac6f403 100644 --- a/examples/src/prompts/semantic_similarity_example_selector_custom_retriever.ts +++ b/examples/src/prompts/semantic_similarity_example_selector_custom_retriever.ts @@ -11,9 +11,19 @@ const pinecone = new Pinecone(); const pineconeIndex = pinecone.Index(process.env.PINECONE_INDEX!); +/** + * Pinecone allows you to partition the records in an index into namespaces. + * Queries and other operations are then limited to one namespace, + * so different requests can search different subsets of your index. + * Read more about namespaces here: https://docs.pinecone.io/guides/indexes/use-namespaces + * + * NOTE: If you have namespace enabled in your Pinecone index, you must provide the namespace when creating the PineconeStore. + */ +const namespace = "pinecone"; + const pineconeVectorstore = await PineconeStore.fromExistingIndex( new OpenAIEmbeddings(), - { pineconeIndex } + { pineconeIndex , namespace } ); const pineconeMmrRetriever = pineconeVectorstore.asRetriever({ From 6b8501cd7726f283f1da790e2ddd2c871cffb151 Mon Sep 17 00:00:00 2001 From: bracesproul Date: Tue, 23 Jul 2024 10:03:44 -0700 Subject: [PATCH 2/2] yarn format --- examples/src/indexes/vector_stores/pinecone/mmr.ts | 6 +++--- examples/src/indexes/vector_stores/pinecone/query_docs.ts | 6 +++--- ...mantic_similarity_example_selector_custom_retriever.ts | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/src/indexes/vector_stores/pinecone/mmr.ts b/examples/src/indexes/vector_stores/pinecone/mmr.ts index 779cee9f73ed..10a85253b3ea 100644 --- a/examples/src/indexes/vector_stores/pinecone/mmr.ts +++ b/examples/src/indexes/vector_stores/pinecone/mmr.ts @@ -12,11 +12,11 @@ const pinecone = new Pinecone(); const pineconeIndex = pinecone.Index(process.env.PINECONE_INDEX!); /** - * Pinecone allows you to partition the records in an index into namespaces. - * Queries and other operations are then limited to one namespace, + * Pinecone allows you to partition the records in an index into namespaces. + * Queries and other operations are then limited to one namespace, * so different requests can search different subsets of your index. * Read more about namespaces here: https://docs.pinecone.io/guides/indexes/use-namespaces - * + * * NOTE: If you have namespace enabled in your Pinecone index, you must provide the namespace when creating the PineconeStore. */ const namespace = "pinecone"; diff --git a/examples/src/indexes/vector_stores/pinecone/query_docs.ts b/examples/src/indexes/vector_stores/pinecone/query_docs.ts index ff32b366cb3f..6294067724ec 100644 --- a/examples/src/indexes/vector_stores/pinecone/query_docs.ts +++ b/examples/src/indexes/vector_stores/pinecone/query_docs.ts @@ -12,11 +12,11 @@ const pinecone = new Pinecone(); const pineconeIndex = pinecone.Index(process.env.PINECONE_INDEX!); /** - * Pinecone allows you to partition the records in an index into namespaces. - * Queries and other operations are then limited to one namespace, + * Pinecone allows you to partition the records in an index into namespaces. + * Queries and other operations are then limited to one namespace, * so different requests can search different subsets of your index. * Read more about namespaces here: https://docs.pinecone.io/guides/indexes/use-namespaces - * + * * NOTE: If you have namespace enabled in your Pinecone index, you must provide the namespace when creating the PineconeStore. */ const namespace = "pinecone"; diff --git a/examples/src/prompts/semantic_similarity_example_selector_custom_retriever.ts b/examples/src/prompts/semantic_similarity_example_selector_custom_retriever.ts index a96d0ac6f403..d40f014bf131 100644 --- a/examples/src/prompts/semantic_similarity_example_selector_custom_retriever.ts +++ b/examples/src/prompts/semantic_similarity_example_selector_custom_retriever.ts @@ -12,18 +12,18 @@ const pinecone = new Pinecone(); const pineconeIndex = pinecone.Index(process.env.PINECONE_INDEX!); /** - * Pinecone allows you to partition the records in an index into namespaces. - * Queries and other operations are then limited to one namespace, + * Pinecone allows you to partition the records in an index into namespaces. + * Queries and other operations are then limited to one namespace, * so different requests can search different subsets of your index. * Read more about namespaces here: https://docs.pinecone.io/guides/indexes/use-namespaces - * + * * NOTE: If you have namespace enabled in your Pinecone index, you must provide the namespace when creating the PineconeStore. */ const namespace = "pinecone"; const pineconeVectorstore = await PineconeStore.fromExistingIndex( new OpenAIEmbeddings(), - { pineconeIndex , namespace } + { pineconeIndex, namespace } ); const pineconeMmrRetriever = pineconeVectorstore.asRetriever({