document.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * Interface for interacting with a document.
  3. */
  4. export class Document {
  5. constructor(fields) {
  6. Object.defineProperty(this, "pageContent", {
  7. enumerable: true,
  8. configurable: true,
  9. writable: true,
  10. value: void 0
  11. });
  12. Object.defineProperty(this, "metadata", {
  13. enumerable: true,
  14. configurable: true,
  15. writable: true,
  16. value: void 0
  17. });
  18. // The ID field is optional at the moment.
  19. // It will likely become required in a future major release after
  20. // it has been adopted by enough vectorstore implementations.
  21. /**
  22. * An optional identifier for the document.
  23. *
  24. * Ideally this should be unique across the document collection and formatted
  25. * as a UUID, but this will not be enforced.
  26. */
  27. Object.defineProperty(this, "id", {
  28. enumerable: true,
  29. configurable: true,
  30. writable: true,
  31. value: void 0
  32. });
  33. this.pageContent =
  34. fields.pageContent !== undefined ? fields.pageContent.toString() : "";
  35. this.metadata = fields.metadata ?? {};
  36. this.id = fields.id;
  37. }
  38. }