Given equations of motion, how can we check if there is a lagrangian from which we can derive them? [duplicate]

Suppose we are given a set of equations of motion for $$N$$ bodies, which generically will go like this

$$$$\frac{d^2\mathbf{r}_i}{dt^2}=\mathbf{F}_i \left((\mathbf{r}_i)_{1 \leq i \leq N}, (\frac{d \mathbf{r}_i}{dt})_{1 \leq i \leq N}, (\frac{d^2 \mathbf{r}_i}{dt^2})_{1 \leq i \leq N} \right)$$$$ $$\mathbf{r}_i$$ is the position of body $$i$$ and $$\mathbf{F}_i$$ is just the sum of all the generalized force terms acting on it. $$\mathbf{F}_i$$ could depend on the positions $$\mathbf{r}_i$$ and velocities $$\frac{d \mathbf{r}_i}{d t}$$ of any of the other bodies, but also on powers of position and velocity, and even terms involving acceleration.

The question is: If we know $$\mathbf{F}_i$$, how can we know if this equations of motion can be derived from a lagrangian? Is there a systematic way to check that? Is there a systematic way of getting said lagrangian?

The topic of Lagrangian kinetics of constrained dynamics treats the question asked here in the case that $$\mathbf{F}_i$$ depends on the positions and velocities. In particular see chapter 3 of the book on analytical mechanics by Papastavridis. If the forces $$\mathbf{F}_i$$ depend only on the positions $$(\mathbf{r}_i)_{1 \leq i \leq N}$$ of the $$N$$ bodies, they are called potential forces and the explicit form of the corresponding potential in the Lagrangian maybe obtained by calculating the primitive of the force. However, this process is, in general, more challenging when non-potential forces are involved.