| import fs from "fs"; |
| import readline from "readline"; |
| import { QdrantClient } from "@qdrant/js-client-rest"; |
| import path from "path"; |
|
|
| if (!process.env.QDRANT_URL || !process.env.QDRANT_COLLECTION) { |
| throw new Error("Please set QDRANT_URL and QDRANT_COLLECTION env variables"); |
| } |
|
|
| |
| |
| |
| |
|
|
| export async function RUN() { |
| const client = new QdrantClient({ url: process.env.QDRANT_URL }); |
|
|
| let index = 0; |
|
|
| const file = path.join( |
| process.cwd(), |
| "data", |
| "swiss-code-of-obligations-en-paraphrase-multilingual-mpnet-base-v2.jsonl" |
| ); |
| readLines(file, async (line) => { |
| index++; |
| const title = line.headings.slice(-1)[0]; |
| const { vector, ...payload } = line; |
|
|
| console.log(index, title); |
|
|
| await client.upsert(process.env.QDRANT_COLLECTION, { |
| wait: true, |
| points: [{ id: index, vector, payload: { title, ...payload } }], |
| }); |
| }); |
| } |
|
|
| |
| await RUN(); |
|
|
| |
| export async function readLines(filePath, func) { |
| const fileStream = fs.createReadStream(filePath); |
|
|
| const rl = readline.createInterface({ |
| input: fileStream, |
| crlfDelay: Infinity, |
| }); |
|
|
| for await (const line of rl) { |
| await func(JSON.parse(line)); |
| } |
| } |
|
|