Skip to content

Commit

Permalink
Profile grows getCachedEmbeddingVector and cacheEmbeddingVector.
Browse files Browse the repository at this point in the history
Part of #55. Part of #25.
  • Loading branch information
jkomoros committed Jul 23, 2023
1 parent dad8cae commit 2ce46cc
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
EmbeddingModelID,
LeafValue,
MemoryID,
RawEmbeddingVector,
SeedPacketAbsoluteRemoteLocation,
StoreID,
StoreKey,
Expand Down Expand Up @@ -85,10 +86,17 @@ export class Profile{
}
};

_cachedEmbeddings : {
[model in EmbeddingModelID]?: {
[text : string]: RawEmbeddingVector
}
};

constructor() {
this._memories = {};
this._stores = {};
this._allowedFetches = {};
this._cachedEmbeddings = {};
}

set garden(val : Garden) {
Expand All @@ -108,6 +116,20 @@ export class Profile{
console.log(message, ...optionalParams);
}

getCachedEmbeddingVector(model : EmbeddingModelID, text : string) : RawEmbeddingVector | undefined {
const subMap = this._cachedEmbeddings[model];
if (!subMap) return undefined;
return subMap[text];
}

cacheEmbeddingVector(model : EmbeddingModelID, text : string, vector : RawEmbeddingVector) {
if (!this._cachedEmbeddings[model]) this._cachedEmbeddings[model] = {};
//Yes, typescript, this will be set...
const subObj = this._cachedEmbeddings[model];
if (!subObj) return;
subObj[text] = vector;
}

//Whether to allow fetch of a given location.
async allowFetch(remotePacketLocation : SeedPacketAbsoluteRemoteLocation, domain : URLDomain) : Promise<boolean> {
if (this._allowedFetches[remotePacketLocation]) {
Expand Down

0 comments on commit 2ce46cc

Please sign in to comment.