Langchain
LangChain has many useful integrations with various ecosystem tools, like:
import { PineconeClient } from "@pinecone-database/pinecone";
import { OpenAIEmbeddings } from "langchain/embeddings/openai";
import { PineconeStore } from "langchain/vectorstores/pinecone";
import { ChatCompletion, SystemMessage, UserMessage } from 'ai-jsx/completion-components';
function getVectorStore() {
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);
const vectorStore = await PineconeStore.fromExistingIndex(
new OpenAIEmbeddings(),
{ pineconeIndex }
);
}
function MyDocsFunction({query}: {query: string}) {
const docs = await getVectorStore().similaritySearch(query);
return <ChatCommpletion>
<SystemMessage>
You are a knowledge base agent who answers questions based on these docs: {JSON.stringify(docs)}
</SystemMessage>
<UserMessage>{query}</UserMessage>
</ChatCompletion>
}