An encoding method is provided for an encoding apparatus. The method includes obtaining a target paragraph and a preset database, and inputting the target paragraph and preset database into a memory encoding model, obtaining, in an input layer, an original vector set of the target paragraph and a knowledge vector set of the preset database, obtaining, in a first memory layer, a first target sentence matrix according to the original vector set and the knowledge vector set, and obtaining, in an output layer, a paragraph vector of the target paragraph according to the first target sentence matrix, and performing processing based on the paragraph vector.