-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopulate.js
More file actions
28 lines (22 loc) · 913 Bytes
/
populate.js
File metadata and controls
28 lines (22 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import * as dotenv from 'dotenv'
import { DirectoryLoader } from 'langchain/document_loaders/fs/directory'
import { TextLoader } from 'langchain/document_loaders/fs/text'
import { PineconeClient } from '@pinecone-database/pinecone'
import { createPineconeIndex } from './utils/createPineconeIndex.js'
import { updatePinecone } from './utils/updatePinecone.js'
dotenv.config()
const loader = new DirectoryLoader('./documents', {
'.txt': (path) => new TextLoader(path)
})
const docs = await loader.load()
const client = new PineconeClient()
await client.init({
apiKey: process.env.PINECONE_API_KEY,
environment: process.env.PINECONE_ENVIRONMENT
})
const indexName = process.env.PINECONE_INDEX_NAME
const vectorDimension = process.env.PINECONE_VECTOR_DIMENSION
;(async () => {
await createPineconeIndex(client, indexName, vectorDimension)
await updatePinecone(client, indexName, docs)
})()