Skip to content

Commit

Permalink
Merge branch 'fewfixes' of https://github.com/tarrencev/eliza into ta…
Browse files Browse the repository at this point in the history
…rrencev-fewfixes
  • Loading branch information
ponderingdemocritus committed Nov 20, 2024
2 parents fec2d59 + 759ea39 commit 737811f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 38 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ twitter_cookies.json
timeline_cache.json

*.sqlite
agent
characters/

packages/core/src/providers/cache
Expand Down
43 changes: 7 additions & 36 deletions packages/adapter-postgres/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,42 +290,13 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter {
match_count: number;
unique: boolean;
}): Promise<Memory[]> {
const client = await this.pool.connect();
try {
let sql = `
SELECT *,
1 - (embedding <-> $3) as similarity
FROM memories
WHERE type = $1 AND "roomId" = $2
`;

if (params.unique) {
sql += ` AND "unique" = true`;
}

sql += ` AND 1 - (embedding <-> $3) >= $4
ORDER BY embedding <-> $3
LIMIT $5`;

const { rows } = await client.query(sql, [
params.tableName,
params.roomId,
params.embedding,
params.match_threshold,
params.match_count,
]);

return rows.map((row) => ({
...row,
content:
typeof row.content === "string"
? JSON.parse(row.content)
: row.content,
similarity: row.similarity,
}));
} finally {
client.release();
}
return await this.searchMemoriesByEmbedding(params.embedding, {
match_threshold: params.match_threshold,
count: params.match_count,
roomId: params.roomId,
unique: params.unique,
tableName: params.tableName,
});
}

async getMemories(params: {
Expand Down
2 changes: 1 addition & 1 deletion packages/client-discord/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,10 @@ export class MessageManager {
roomId,
content,
createdAt: message.createdTimestamp,
embedding: embeddingZeroVector,
};

if (content.text) {
await this.runtime.messageManager.addEmbeddingToMemory(memory);
await this.runtime.messageManager.createMemory(memory);
}

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export class MemoryManager implements IMemoryManager {
elizaLogger.debug("Memory already exists, skipping");
return;
}

await this.runtime.databaseAdapter.createMemory(
memory,
this.tableName,
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,14 @@ export class AgentRuntime implements IAgentRuntime {
text: knowledgeItem,
},
});

const fragments = await splitChunks(knowledgeItem, 1200, 200);
for (const fragment of fragments) {
const embedding = await embed(this, fragment);
await this.knowledgeManager.createMemory({
id: stringToUuid(fragment),
// We namespace the knowledge base uuid to avoid id
// collision with the document above.
id: stringToUuid(knowledgeId + fragment),
roomId: this.agentId,
agentId: this.agentId,
userId: this.agentId,
Expand Down

0 comments on commit 737811f

Please sign in to comment.