Skip to content

Optimize upstash search #9

@preetamslot

Description

@preetamslot

Hi,
I am not sure, but looking at the code for the upstash search I see this:

try {
      // Search for documents - include namespace to improve relevance
      
      // Include namespace in search to boost relevance
      const searchQuery = `${query} ${namespace}`
      
      const searchResults = await searchIndex.search({
        query: searchQuery,
        limit: config.search.maxResults,
        reranking: true
      })
      
      
      // Filter to only include documents from the correct namespace
      documents = searchResults.filter((doc) => {
        const docNamespace = doc.metadata?.namespace
        const matches = docNamespace === namespace
        if (!matches && doc.metadata?.namespace) {
          // Only log first few mismatches to avoid spam
          if (documents.length < 3) {
          }
        }
        return matches
      })
....

Why don't you use the filter function like:

  const searchResults = await searchIndex.search({
        query: query,
        limit: config.search.maxResults,
        filter: `@metadata.namespace = "${namespace}"`,
        reranking: true,
      });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions