Let K be a field and A be a commutative associative K-algebra which is an integral domain. The Lie algebra Der A of all K-derivations of A is an A-module in a natural way and if R is the quotient field of A, then RDer A is a vector space over R. It is proved that if L is a nilpotent subalgebra of RDer A of rank k over R (i.e. such that dim_{R}RL=k), then the derived length of L is at most k and L is finite dimensional over its field of constants. In case of solvable Lie algebras over a field of characteristic zero their derived length does not exceed 2k. Nilpotent and solvable Lie algebras of rank 1 and 2 (over R) from the Lie algebra RDer A are characterized. As a consequence we obtain the same estimations for nilpotent and solvable Lie algebras of vector fields with polynomial, rational, or formal coefficients.