I learned that the Hochschild cohomology of an associative algebra $A$ with a bimodule $M$ is defined using the cochain \begin{align*} \cdots \rightarrow C^n(A,M) \stackrel{d^n}{\longrightarrow} C^{n+1}(A,M) \rightarrow \cdots, \end{align*} where $C^n(A,M)=\mathrm{Hom}(A^n,M)$ and $$d^nf(x_1, \ldots, x_{n+1})=x_1 f(x_2,\ldots, x_{n+1})+ \sum \limits_{i=1}^n(1)^if(x_1, \ldots, x_{i1},x_i x_{i+1}, \ldots, x_{n+1})+(1)^{n+1} f(x_1, \ldots, x_n)x_{n+1}.$$ I also learned that the cohomology theory of other algebraic structures are studied, for example the ChevalleyEilenberg cohomology of Lie algebras, the cohomology of 3Lie algebras, the cohomology of Leibniz algebras and so on. I find that the cochains $C^n(A,M)$ and the differential $d^n$ are quite different for different algebraic structures. So I want to know whether there are some rules when consider the cohomology of an algebra? For example, given an algebra (associative, Lie, Leibniz,...) and a representation $M$ of the algebra, how should we define $C^n(A,M)$ and how should we define $d^n$ to give an appropriate cohomology of the algebra?

$\begingroup$ Maybe look at ncatlab.org/nlab/show/monadic+cohomology $\endgroup$– Benjamin SteinbergCommented Sep 22, 2022 at 18:45

$\begingroup$ See also mathoverflow.net/questions/3078/… $\endgroup$– Benjamin SteinbergCommented Sep 22, 2022 at 18:46

2$\begingroup$ You are mentioning algebraic structures that are encoded by Koszul operads, so you can use that. it is probable that any other choice is either wrong or coincides with this one. $\endgroup$– Mariano SuárezÁlvarezCommented Sep 23, 2022 at 0:58

1$\begingroup$ For multilinear theories (governed by algebraic operads) you can consult the literature Algebraic Operads (Fresse, LodayVallette) and similar references, which define the cohomology theory you want even if the operad is not Koszul. If it is, you just want to consider a complex of the form $ C^*(V) = \hom(P^{\rm{dual}}(V),V)$ which is twisted "twice" using the canonical twisting cochain of a Koszul operad. $\endgroup$– PedroCommented Oct 6, 2022 at 8:29
2 Answers
There is a tremendous amount of abstract formalism answering this question in various levels of generality depending on what you want to do. I'll pick one in the middle: the machinery of derived functors is, roughly speaking, an abstract formalism allowing you to recover a notion of cohomology $H^n$ starting from, say, a left exact functor $H^0$ between abelian categories (more general setups are also possible). So to find interesting notions of cohomology we can look for such functors. All of the functors I discuss below are actually representable so their derived functors are "derived homs."
You can think of group cohomology, where $H^0(G, M)$ is the functor $M^G$ of invariants, and Lie algebra cohomology, where $H^0(\mathfrak{g}, M)$ is again the functor of invariants, as motivating examples; here cohomology is "derived invariants." Hochschild cohomology can also be interpreted this way, where $H^0(A, M)$ is the functor of invariants in the sense $\{ m \in M : \forall a \in A, am = ma \}$. This is maybe a bit more mysterious but at least it's easier to understand than the entire Hochschild complex.
The phrasing of your question actually invites the following question: what is the cohomology of a module (as opposed to a bimodule) $M$ over an algebra $A$? And our derived functor setup encourages us to ask: well, what left exact functors take as input such a module? As mentioned, the three examples we considered above are all actually representable functors $M \mapsto \text{Hom}(N, M)$ where $N$ was a special module (the trivial module of $G$ resp. $\mathfrak{g}$ in the group and Lie algebra case, and $A$ as a bimodule over itself in the Hochschild case). If we just consider (say, left) modules over an algebra $A$ the only special module in sight is $A$ itself, but the corresponding functor $\text{Hom}_A(A, M)$ just spits out $M$ again; in particular it's not only left exact but exact so doesn't have any interesting derived functors. In this setting we should just consider an arbitrary hom $\text{Hom}_A(N, M)$ and we recover Ext.
So, given some algebraic structure $A$, you can first ask whether it has some abelian category of modules $M$ over it in some sense, and you can second ask whether there are any "special" modules $N$, then consider the derived functors of $\text{Hom}(N, )$. That'll recover some notion of cohomology.
To get a specific complex computing this thing you pick a specific resolution of $N$; e.g. for group cohomology the usual complex computing it comes from taking a free resolution of the trivial module called the bar resolution. Thinking in terms of derived functors gives you the flexibility to choose other resolutions as appropriate, or to not choose resolutions at all and just do computations using long exact sequences or spectral sequences etc.

$\begingroup$ You want $\forall a \in A,\,a m = m$, not $a m = m a$, right? $\endgroup$– LSpiceCommented Oct 7, 2022 at 23:34

2$\begingroup$ @LSpice: In that sentence, he is talking about Hochschild, not group, cohomology. $\endgroup$ Commented Oct 7, 2022 at 23:43
As well put in the previous answer, derived functors are a good tool for computing homology of algebraic structures, and their introduction during the '50s gave a unified approach to address (co)homology of groups, Lie algebras and associative algebras (the inauguration of the Homological Algebra field).
Alternatively, one can also use (as already mentioned in the comments) the more recent Operad Theory. An operad is an object capable of encoding certain algebraic structures: for example, there are the operads of Lie algebras, associative algebras, commutative algebras, Leibniz algebras,…. When an operad is quadratic (which is satisfied by all of the examples above), it is possible to define a complex, which induces the socalled operadic homology. In this manner, one can recover the (co)homology theories of Hochschild (Associative), Chevalley and Eilenberg (Lie), Harrison (Commutative) and Loday (Leibniz).
Actually, more could be said: according to Loday & Valette, this approach showed what is the correct chain complex to compute the homology of Poisson algebras — mathematicians had used a different complex until then.
P.S.: Even though, this does not mean that any algebraic homological theory may be given by operads or derived functors. For instance, I am not acquainted on how one can obtain Cyclic Homology (of an associative algebra) in terms of operads or (usual) derived functors.
All details may be seen in Loday & Valette's book Algebraic operads (9.1.6, 9.1.8 13.1.4, 13.2.2, 13.3.8, 13.5.4,…).