Skip to content
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

Added config for topK for Pinecone #333

Open
wants to merge 1 commit into
base: main
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
10 changes: 6 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
OPENAI_API_KEY=
OPENAI_API_KEY =

# Update these with your pinecone details from your dashboard.
# PINECONE_INDEX_NAME is in the indexes tab under "index name" in blue
# PINECONE_ENVIRONMENT is in indexes tab under "Environment". Example: "us-east1-gcp"
PINECONE_API_KEY=
PINECONE_ENVIRONMENT=
PINECONE_INDEX_NAME=
# PINECONE_TOPK is the number of related sources you want for each prompt, defaults to 4
PINECONE_API_KEY =
PINECONE_ENVIRONMENT =
PINECONE_INDEX_NAME =
PINECONE_TOPK =
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ next-env.d.ts

#Notion_db
/Notion_DB

/docs
4 changes: 3 additions & 1 deletion config/pinecone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ const PINECONE_INDEX_NAME = process.env.PINECONE_INDEX_NAME ?? '';

const PINECONE_NAME_SPACE = 'pdf-test'; //namespace is optional for your vectors

export { PINECONE_INDEX_NAME, PINECONE_NAME_SPACE };
const PINECONE_TOPK: number = +(process.env.PINECONE_TOPK ?? 4);

export { PINECONE_INDEX_NAME, PINECONE_NAME_SPACE, PINECONE_TOPK };
3 changes: 2 additions & 1 deletion utils/makechain.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { OpenAI } from 'langchain/llms/openai';
import { PineconeStore } from 'langchain/vectorstores/pinecone';
import { ConversationalRetrievalQAChain } from 'langchain/chains';
import { PINECONE_TOPK } from '@/config/pinecone';

const CONDENSE_PROMPT = `Given the following conversation and a follow up question, rephrase the follow up question to be a standalone question.

Expand All @@ -26,7 +27,7 @@ export const makeChain = (vectorstore: PineconeStore) => {

const chain = ConversationalRetrievalQAChain.fromLLM(
model,
vectorstore.asRetriever(),
vectorstore.asRetriever(PINECONE_TOPK),
{
qaTemplate: QA_PROMPT,
questionGeneratorTemplate: CONDENSE_PROMPT,
Expand Down