Skip to content

Context Search With Documents (Personalization) - Revised #1254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 54 commits into
base: mainline
Choose a base branch
from

Conversation

vicilliar
Copy link
Contributor

@vicilliar vicilliar commented Jun 26, 2025

Updated version of personalization PR intended for 2.21.0 which was reverted due to an issue with the Vespa client.
Differences from old personalization PR:
-Use persistent SSL context instead of persistent transport, because it caused hanging during concurrent requests. Performance gains are comparable.
-Integration test added for concurrent get documents requests to ensure no hanging

Change Summary

Supports new key documents in context parameter of search. This allows for a dict of doc_id:weight pairs to be provided by user for vectors to be extracted and interpolated for tensor search or hybrid search with tensor retrieval or ranking.

Updated example context object:

    {
        "tensor": [{"vector": [1 for i in range(768)], "weight": 1}], 
        "documents": {
            "ids": {"doc1": 1},
            "parameters": {
                "excludeInputDocuments": False,
                "tensorFields": ["text_field_1"],
                "concurrency": 10
            }
        }
    }

-Interpolation is now done on all vectors (query, context.tensor, context.document) instead of previous behavior of weighted average.
-Absolute value is now used when summing vector weights in interpolation (This makes ZeroSumWeightsError obsolete, we now use AllZeroWeightsError instead)
-Interpolation logic implemented in numpy.
-Fixed some error messages for hybrid / pydantic model validation.

New Env Vars:
-MARQO_MAX_SEARCH_CONTEXT_DOCS - aximum number of documents that can be used as context documents in a search request.

The following optimizations have been implemented:
-Getting doc vectors fetches only essential embeddings fields from Vespa
-A persistent SSL Context is created upon vespa client initialization and is used for the verify param of every async client instantiation. This saves time spent creating new contexts.
-Index is fetched from cache instead of Vespa
-Fetched doc vectors are not formatted into document form with Pydantic. Vectors are just used directly

Related Jira Ticket

https://s2search.atlassian.net/jira/polaris/projects/MOSD/ideas/view/4863474?selectedIssue=MOSD-23&issueViewLayout=sidebar&issueViewSection=overview&atlOrigin=eyJpIjoiNzcyNDBkNzVjM2JhNDE0Y2I4ODUzNDY3YTc2MmE0ZmUiLCJwIjoiaiJ9

Checklist

For new field types:

  • Tests cover score modifier usage of this new type
  • Test indexes updated to cover the new type for all APIs (add docs, search, partial update, etc.)

@vicilliar vicilliar requested review from farshidz and wanliAlex and removed request for farshidz July 2, 2025 06:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant