documentsService.js 963 B

1234567891011121314151617181920212223242526272829303132
  1. import { config } from "../config/index.js";
  2. import { qdrant } from "./qdrantClient.js";
  3. export async function listDocuments({ limit, offset }) {
  4. const collectionName = config.qdrant.collection;
  5. let points;
  6. try {
  7. points = await qdrant.scroll(collectionName, {
  8. limit,
  9. offset: offset || undefined,
  10. with_payload: true,
  11. with_vector: false
  12. });
  13. } catch (err) {
  14. const status = err?.status ?? err?.statusCode ?? err?.response?.status ?? null;
  15. if (Number(status) === 404) return { items: [], nextOffset: null };
  16. throw err;
  17. }
  18. const items = (points?.points ?? []).map((p) => ({
  19. id: p.id,
  20. source: p.payload?.source ?? null,
  21. title: p.payload?.title ?? null,
  22. text: p.payload?.text ?? null,
  23. chunkIndex: p.payload?.chunkIndex ?? null,
  24. metadata: p.payload?.metadata ?? null
  25. }));
  26. const nextOffset = points?.next_page_offset ?? points?.nextPageOffset ?? null;
  27. return { items, nextOffset };
  28. }