-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from Barqawiz/candidate-1.3.5
Candidate 1.3.7 - add support for llama-code and llama-python. - upgrade the semantic search to support huge data memory search using `SemanticSearchPaging`. - update the documentation.
- Loading branch information
Showing
16 changed files
with
860 additions
and
677 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const { SemanticSearch } = require('./SemanticSearch'); // assuming path | ||
|
||
class SemanticSearchPaging extends SemanticSearch { | ||
constructor(keyValue, provider, pivotItem, numberOfMatches) { | ||
super(keyValue, provider); | ||
this.pivotItem = pivotItem; | ||
this.numberOfMatches = numberOfMatches; | ||
this.textAndMatches = []; // To store { text: '...', similarity: 0.9 } results | ||
this.topMatches = []; | ||
} | ||
|
||
async addNewData(newSearchItems) { | ||
// get the best matches for new items | ||
const newMatches = await super.getTopMatches(this.pivotItem, newSearchItems, newSearchItems.length); | ||
|
||
// map the matches format | ||
const newMatchesWithText = newMatches.map(match => ({ | ||
text: newSearchItems[match.index], | ||
score: match.similarity, | ||
})); | ||
|
||
// combine with old top matches and sort | ||
this.topMatches = [...this.topMatches, ...newMatchesWithText] | ||
.sort((a, b) => b.score - a.score) | ||
.slice(0, this.numberOfMatches); | ||
} | ||
|
||
getCurrentTopMatches() { | ||
return this.topMatches; | ||
} | ||
|
||
clean() { | ||
this.topMatches = []; | ||
} | ||
} | ||
|
||
module.exports = { SemanticSearchPaging }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require('dotenv').config(); | ||
const assert = require('assert'); | ||
const { SemanticSearchPaging } = require('../../function/SemanticSearchPaging'); | ||
const { SupportedEmbedModels } = require('../../controller/RemoteEmbedModel'); | ||
|
||
const openaiApiKey = process.env.OPENAI_API_KEY; | ||
const cohereApiKey = process.env.COHERE_API_KEY; | ||
|
||
const pivotItem = 'Hello from IntelliNode'; | ||
|
||
const openaiSemanticSearch = new SemanticSearchPaging(openaiApiKey, | ||
SupportedEmbedModels.OPENAI, | ||
pivotItem, 2); | ||
const cohereSemanticSearch = new SemanticSearchPaging(cohereApiKey, | ||
SupportedEmbedModels.COHERE, | ||
pivotItem, 2); | ||
|
||
async function addToSessionAndTest(semanticSearch, newSearchItems) { | ||
|
||
await semanticSearch.addNewData( newSearchItems); | ||
const results = semanticSearch.getCurrentTopMatches(); | ||
|
||
console.log('Semantic Search Session Results:', results); | ||
assert(results.length <= semanticSearch.numberOfMatches, 'Test passed'); | ||
} | ||
|
||
(async () => { | ||
|
||
// semantic search with openai embedding | ||
await addToSessionAndTest(openaiSemanticSearch, ['Greetings from IntelliNode!', 'Saluti da IntelliNode!']); | ||
await addToSessionAndTest(openaiSemanticSearch, ['Hola desde IntelliNode!', 'Bonjour de IntelliNode!']); | ||
|
||
openaiSemanticSearch.clean(); | ||
|
||
// semantic search with cohere embedding | ||
await addToSessionAndTest(cohereSemanticSearch, ['Greetings from IntelliNode!', 'Bonjour de IntelliNode!']); | ||
await addToSessionAndTest(cohereSemanticSearch, ['Hola desde IntelliNode!', 'Saluti da IntelliNode!']); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.