Fix: Update all search calls to 2-parameter API

This commit is contained in:
David Snelling 2025-08-26 12:49:31 -07:00
parent 9c87982a7d
commit ef1745af8f
6 changed files with 32 additions and 34 deletions

6
.gitignore vendored
View file

@ -51,17 +51,17 @@ temp/
# Private/confidential files # Private/confidential files
PLAN.md PLAN.md
CLAUDE.md
INTERNAL_NOTES.md INTERNAL_NOTES.md
TODO_PRIVATE.md TODO_PRIVATE.md
*.tar.gz *.tar.gz
# Models (downloaded at runtime) # Models (downloaded at runtime)
models/CLAUDE.md models/
.CLAUDE.md
# Development planning files (not for commit) # Development planning files (not for commit)
PLAN.md PLAN.md
CLAUDE.md
# Backup folders # Backup folders
backup-* backup-*

View file

@ -3205,9 +3205,11 @@ export class BrainyData<T = any> implements BrainyDataInterface<T> {
const searchK = options.cursor ? k + 20 : k // Get extra results for filtering const searchK = options.cursor ? k + 20 : k // Get extra results for filtering
// Perform regular search // Perform regular search
const allResults = await this.search(queryVectorOrData, searchK, { const { cursor, ...searchOptions } = options
...options, const allResults = await this.search(queryVectorOrData, {
skipCache: options.skipCache limit: searchK,
nounTypes: searchOptions.nounTypes,
metadata: searchOptions.filter
}) })
let results = allResults let results = allResults
@ -3469,11 +3471,10 @@ export class BrainyData<T = any> implements BrainyDataInterface<T> {
// If no relationType is specified, use the original vector similarity search // If no relationType is specified, use the original vector similarity search
const k = (options.limit || 10) + 1 // Add 1 to account for the original entity const k = (options.limit || 10) + 1 // Add 1 to account for the original entity
const searchResults = await this.search(entity.vector, k, { const searchResults = await this.search(entity.vector, {
forceEmbed: false, limit: k,
nounTypes: options.nounTypes, excludeDeleted: false,
includeVerbs: options.includeVerbs, nounTypes: options.nounTypes
searchMode: options.searchMode
}) })
// Filter out the original entity and limit to the requested number // Filter out the original entity and limit to the requested number
@ -5802,12 +5803,10 @@ export class BrainyData<T = any> implements BrainyDataInterface<T> {
const queryVector = await this.embed(query) const queryVector = await this.embed(query)
// Search using the embedded vector with metadata filtering // Search using the embedded vector with metadata filtering
const results = await this.search(queryVector, k, { const results = await this.search(queryVector, {
limit: k,
nounTypes: options.nounTypes, nounTypes: options.nounTypes,
includeVerbs: options.includeVerbs, metadata: options.metadata
searchMode: options.searchMode,
metadata: options.metadata,
forceEmbed: false // Already embedded
}) })
// Track search performance // Track search performance
@ -6683,11 +6682,8 @@ export class BrainyData<T = any> implements BrainyDataInterface<T> {
for (const [service, fieldNames] of Object.entries(serviceFieldMappings)) { for (const [service, fieldNames] of Object.entries(serviceFieldMappings)) {
for (const fieldName of fieldNames) { for (const fieldName of fieldNames) {
// Search using the specific field name for this service // Search using the specific field name for this service
const results = await this.search(searchTerm, k, { const results = await this.search(searchTerm, {
searchField: fieldName, limit: k
service,
includeVerbs: options.includeVerbs,
searchMode: options.searchMode
}) })
// Add results to the combined list // Add results to the combined list

View file

@ -67,8 +67,8 @@ export class BrainyChat {
// Search for the most recent chat message using Brainy's search // Search for the most recent chat message using Brainy's search
const recentMessages = await this.brainy.search( const recentMessages = await this.brainy.search(
'recent chat conversation', 'recent chat conversation',
1,
{ {
limit: 1,
nounTypes: [NounType.Message], nounTypes: [NounType.Message],
metadata: { metadata: {
messageType: 'chat' messageType: 'chat'
@ -198,7 +198,9 @@ export class BrainyChat {
await this.addMessage(question, 'user') await this.addMessage(question, 'user')
// Search for relevant content using Brainy's search // Search for relevant content using Brainy's search
const searchResults = await this.brainy.search(question, options?.maxSources || 5) const searchResults = await this.brainy.search(question, {
limit: options?.maxSources || 5
})
// Generate a template-based response // Generate a template-based response
let response = '' let response = ''
@ -242,8 +244,8 @@ export class BrainyChat {
// Search for messages in this session using Brainy's search // Search for messages in this session using Brainy's search
const messageNouns = await this.brainy.search( const messageNouns = await this.brainy.search(
'', // Empty query to get all messages '', // Empty query to get all messages
limit,
{ {
limit: limit,
nounTypes: [NounType.Message], nounTypes: [NounType.Message],
metadata: { metadata: {
sessionId: this.currentSessionId, sessionId: this.currentSessionId,
@ -286,8 +288,8 @@ export class BrainyChat {
try { try {
const results = await this.brainy.search( const results = await this.brainy.search(
options?.semanticSearch !== false ? query : '', options?.semanticSearch !== false ? query : '',
options?.limit || 20,
{ {
limit: options?.limit || 20,
nounTypes: [NounType.Message], nounTypes: [NounType.Message],
metadata metadata
} }
@ -308,8 +310,8 @@ export class BrainyChat {
try { try {
const sessionNouns = await this.brainy.search( const sessionNouns = await this.brainy.search(
'', '',
limit,
{ {
limit: limit,
nounTypes: [NounType.Concept], nounTypes: [NounType.Concept],
metadata: { metadata: {
sessionType: 'chat' sessionType: 'chat'
@ -409,8 +411,8 @@ export class BrainyChat {
// Find previous message to create conversation flow using VerbType.Precedes // Find previous message to create conversation flow using VerbType.Precedes
const previousMessages = await this.brainy.search( const previousMessages = await this.brainy.search(
'', '',
1,
{ {
limit: 1,
nounTypes: [NounType.Message], nounTypes: [NounType.Message],
metadata: { metadata: {
sessionId: this.currentSessionId, sessionId: this.currentSessionId,
@ -435,8 +437,8 @@ export class BrainyChat {
try { try {
const sessionNouns = await this.brainy.search( const sessionNouns = await this.brainy.search(
'', '',
1,
{ {
limit: 1,
nounTypes: [NounType.Concept], nounTypes: [NounType.Concept],
metadata: { metadata: {
sessionType: 'chat' sessionType: 'chat'
@ -460,8 +462,8 @@ export class BrainyChat {
try { try {
const messageNouns = await this.brainy.search( const messageNouns = await this.brainy.search(
'', '',
limit,
{ {
limit: limit,
nounTypes: [NounType.Message], nounTypes: [NounType.Message],
metadata: { metadata: {
sessionId: sessionId, sessionId: sessionId,

View file

@ -52,7 +52,7 @@ async function runExample() {
// Search for similar vectors // Search for similar vectors
console.log('\nSearching for vectors similar to "cat"...') console.log('\nSearching for vectors similar to "cat"...')
const catResults = await db.search(wordEmbeddings['cat'], 3) const catResults = await db.search(wordEmbeddings['cat'], { limit: 3 })
console.log('Results:') console.log('Results:')
for (const result of catResults) { for (const result of catResults) {
const word = const word =
@ -66,7 +66,7 @@ async function runExample() {
// Search for similar vectors // Search for similar vectors
console.log('\nSearching for vectors similar to "fish"...') console.log('\nSearching for vectors similar to "fish"...')
const fishResults = await db.search(wordEmbeddings['fish'], 3) const fishResults = await db.search(wordEmbeddings['fish'], { limit: 3 })
console.log('Results:') console.log('Results:')
for (const result of fishResults) { for (const result of fishResults) {
const word = const word =
@ -96,7 +96,7 @@ async function runExample() {
// Search again to verify shark is gone // Search again to verify shark is gone
console.log('\nSearching for vectors similar to "fish" after deletion...') console.log('\nSearching for vectors similar to "fish" after deletion...')
const fishResultsAfterDeletion = await db.search(wordEmbeddings['fish'], 3) const fishResultsAfterDeletion = await db.search(wordEmbeddings['fish'], { limit: 3 })
console.log('Results:') console.log('Results:')
for (const result of fishResultsAfterDeletion) { for (const result of fishResultsAfterDeletion) {
const word = const word =

View file

@ -2,7 +2,7 @@
* 🧠 BRAINY EMBEDDED PATTERNS * 🧠 BRAINY EMBEDDED PATTERNS
* *
* AUTO-GENERATED - DO NOT EDIT * AUTO-GENERATED - DO NOT EDIT
* Generated: 2025-08-26T19:07:11.967Z * Generated: 2025-08-26T19:40:18.500Z
* Patterns: 220 * Patterns: 220
* Coverage: 94-98% of all queries * Coverage: 94-98% of all queries
* *

View file

@ -355,7 +355,7 @@ export class NaturalLanguageProcessor {
for (const term of terms) { for (const term of terms) {
try { try {
// Search for similar entities in the knowledge base // Search for similar entities in the knowledge base
const results = await this.brain.search(term, 5) const results = await this.brain.search(term, { limit: 5 })
for (const result of results) { for (const result of results) {
if (result.score > 0.8) { // High similarity threshold if (result.score > 0.8) { // High similarity threshold