| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- import { config } from "../config/index.js";
- import { qdrant } from "./qdrantClient.js";
- export async function listDocuments({ limit, offset }) {
- const collectionName = config.qdrant.collection;
- let points;
- try {
- points = await qdrant.scroll(collectionName, {
- limit,
- offset: offset || undefined,
- with_payload: true,
- with_vector: false
- });
- } catch (err) {
- const status = err?.status ?? err?.statusCode ?? err?.response?.status ?? null;
- if (Number(status) === 404) return { items: [], nextOffset: null };
- throw err;
- }
- const items = (points?.points ?? []).map((p) => ({
- id: p.id,
- source: p.payload?.source ?? null,
- title: p.payload?.title ?? null,
- text: p.payload?.text ?? null,
- chunkIndex: p.payload?.chunkIndex ?? null,
- metadata: p.payload?.metadata ?? null,
- ingestedAt: p.payload?.ingestedAt ?? null
- }));
- const nextOffset = points?.next_page_offset ?? points?.nextPageOffset ?? null;
- return { items, nextOffset };
- }
- export async function deleteDocumentsBySource(source) {
- const collectionName = config.qdrant.collection;
- await qdrant.delete(collectionName, {
- wait: true,
- filter: {
- must: [{ key: "source", match: { value: source } }]
- }
- });
- }
|