Commit Graph

35 Commits

Author SHA1 Message Date
Kian Jones
f5c4ab50f4 chore: add ty + pre-commit hook and repeal even more ruff rules (#9504)
* auto fixes

* auto fix pt2 and transitive deps and undefined var checking locals()

* manual fixes (ignored or letta-code fixed)

* fix circular import

* remove all ignores, add FastAPI rules and Ruff rules

* add ty and precommit

* ruff stuff

* ty check fixes

* ty check fixes pt 2

* error on invalid
2026-02-24 10:55:11 -08:00
Kian Jones
25d54dd896 chore: enable F821, F401, W293 (#9503)
* auto fixes

* auto fix pt2 and transitive deps and undefined var checking locals()

* manual fixes (ignored or letta-code fixed)

* fix circular import
2026-02-24 10:55:08 -08:00
Kian Jones
6f746c5225 fix(core): handle Anthropic overloaded errors and Unicode encoding issues (#9305)
* fix: handle Anthropic overloaded_error in streaming interfaces

* fix: handle Unicode surrogates in OpenAI requests

Sanitize Unicode surrogate pairs before sending requests to OpenAI API.
Surrogate pairs (U+D800-U+DFFF) are UTF-16 encoding artifacts that cause
UnicodeEncodeError when encoding to UTF-8.

Fixes Datadog error: 'utf-8' codec can't encode character '\ud83c' in
position 326605: surrogates not allowed

* fix: handle UnicodeEncodeError from lone Unicode surrogates in OpenAI requests

Improved sanitize_unicode_surrogates() to explicitly filter out lone
surrogate characters (U+D800 to U+DFFF) which are invalid in UTF-8.

Previous implementation used errors='ignore' which could still fail in
edge cases. New approach directly checks Unicode code points and removes
any surrogates before data reaches httpx encoding.

Also added sanitization to stream_async_responses() method which was
missing it.

Fixes: 'utf-8' codec can't encode character '\ud83c' in position X:
surrogates not allowed
2026-02-24 10:52:06 -08:00
Kian Jones
01cb00ae10 Revert "fix: truncate oversized text in embedding requests" (#9227)
Revert "fix: truncate oversized text in embedding requests (#9196)"

This reverts commit a9c342087e022519c63d62fb76b72aed8859539b.
2026-02-24 10:52:06 -08:00
Kian Jones
630c147b13 fix: truncate oversized text in embedding requests (#9196)
fix: handle oversized text in embedding requests with recursive chunking

When message text exceeds the embedding model's context length, recursively
split it until all chunks can be embedded successfully.

Changes:
- `tpuf_client.py`: Add `_split_text_in_half()` helper for recursive splitting
- `tpuf_client.py`: Add `_generate_embeddings_with_chunking()` that retries
  with splits on context length errors
- `tpuf_client.py`: Store `message_id` and `chunk_index` columns in Turbopuffer
- `tpuf_client.py`: Deduplicate query results by `message_id`
- `tpuf_client.py`: Use `LettaInvalidArgumentError` instead of `ValueError`
- `tpuf_client.py`: Move LLMClient import to top of file
- `openai_client.py`: Remove fixed truncation (chunking handles this now)
- Add tests for `_split_text_in_half` and chunked query deduplication

🤖 Generated with [Letta Code](https://letta.com)

Co-authored-by: Letta <noreply@letta.com>
2026-02-24 10:52:06 -08:00
github-actions[bot]
101cfefe5e fix: add retry logic for turbopuffer transient network errors (#8635)
Add async retry decorator with exponential backoff to handle transient
network connection errors (httpx.ConnectError) when connecting to
turbopuffer.com. This addresses production errors seen in memgpt-server.

Changes:
- Add `async_retry_with_backoff()` decorator for async methods
- Add `is_transient_error()` helper to identify retryable errors
- Apply retry logic to all turbopuffer network operations
- Retry config: 3 retries, 1s initial delay, 2x backoff, 10% jitter

Fixes #8390
Relates to #8155

🤖 Generated with [Letta Code](https://letta.com)

Co-authored-by: letta-code <248085862+letta-code@users.noreply.github.com>
Co-authored-by: datadog-official[bot] <datadog-official[bot]@users.noreply.github.com>
Co-authored-by: Kian Jones <11655409+kianjones9@users.noreply.github.com>
2026-02-24 10:52:05 -08:00
Kian Jones
2bb4caffc3 fix: remove unused embedding generation (#9013)
* remove unused embedding generation

* prevent double embed

* fix embedding dimension comparison and valueerror
2026-01-29 12:43:53 -08:00
cthomas
870c5955d9 fix: wrap tpuf operations in thread pool (#8615)
* fix: wrap turbopuffer vector writes in thread pool

Turbopuffer library does CPU-intensive base64 encoding of vectors
synchronously in async functions (_async_transform_recursive →
b64encode_vector), blocking the event loop during file uploads.

Solution: Created _run_turbopuffer_write_in_thread() helper that runs
turbopuffer writes in an isolated event loop within a worker thread.

Applied to all vector write operations:
- insert_tools()
- insert_archival_memories()
- insert_messages()
- insert_file_passages()

This prevents pybase64.b64encode_as_string() from blocking the main
event loop during vector encoding.

🐾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta <noreply@letta.com>

* fix: wrap all turbopuffer operations in thread pool

Extended the thread pool wrapping to ALL turbopuffer write operations,
including delete operations, for complete isolation from the main event loop.

All turbopuffer namespace.write() calls now run in isolated event loops
within worker threads, preventing any potential CPU work from blocking.

🐾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta <noreply@letta.com>

---------

Co-authored-by: Letta <noreply@letta.com>
2026-01-19 15:54:37 -08:00
Ari Webb
cdca1a564f fix: conversation id not found in tpuf (#8469)
* fix: conversation id not found in tpuf

* add tests
2026-01-12 10:57:49 -08:00
Charles Packer
ed6284cedb feat: Add conversation_id filtering to message endpoints (#8324)
* feat: Add conversation_id filtering to message list and search endpoints

Add optional conversation_id parameter to filter messages by conversation:
- client.agents.messages.list
- client.messages.list
- client.messages.search

Changes:
- Added conversation_id field to MessageSearchRequest and SearchAllMessagesRequest schemas
- Added conversation_id filtering to list_messages in message_manager.py
- Updated get_agent_recall_async and get_all_messages_recall_async in server.py
- Added conversation_id query parameter to router endpoints
- Updated Turbopuffer client to support conversation_id filtering in searches

Fixes #8320

🤖 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Charles Packer <cpacker@users.noreply.github.com>

* add conversation_id to message and tpuf

* default messages filter for backward compatibility

* add test and auto gen

* fix integration test

* fix test

* update test

---------

Co-authored-by: letta-code <248085862+letta-code@users.noreply.github.com>
Co-authored-by: Charles Packer <cpacker@users.noreply.github.com>
Co-authored-by: christinatong01 <christina@letta.com>
2026-01-12 10:57:48 -08:00
cthomas
a7b3f469ac fix: more user friendly error for tpuf namespace not found [LET-6707] (#8141)
fix: more user friendly error for tpuf namespace not found
2026-01-12 10:57:47 -08:00
Christina Tong
972c61d0b8 chore: fallback to timestamp retrieval for message search [LET-6429] (#6510) 2025-12-15 12:02:33 -08:00
Ari Webb
4d5be22d14 fix: utc for message/passage search tpuf [LET-6109] (#6429)
fix: utc for message/passage search tpuf

Co-authored-by: Ari Webb <ari@letta.com>
2025-12-15 12:02:18 -08:00
Ari Webb
3e02f12dfd feat: add tool embedding and search [LET-6333] (#6398)
* feat: add tool embedding and search

* fix ci

* add env variable for embedding tools

---------

Co-authored-by: Ari Webb <ari@letta.com>
2025-11-26 14:39:40 -08:00
cthomas
6f810d95d8 feat: add semaphore to limit embeddings creation (#6261) 2025-11-24 19:10:11 -08:00
Christina Tong
04611b981c feat: filter messages search endpoint by agent id [LET-6229] (#6246)
* feat: filter messages search endpoint by agent id [LET-6229]

* add autogenerated schema/types
2025-11-24 19:09:33 -08:00
Matthew Zhou
fa38bad3aa feat: Filter out empty chunks in Turbopuffer embedding (#2842) 2025-09-11 14:52:39 -07:00
Matthew Zhou
3a551f4bb7 feat: Add turbopuffer embedder by default [LET-4253] (#4476)
* Adapt to turbopuffer embedder

* Make turbopuffer search more efficient over all source ids

* Combine turbopuffer and pinecone hybrid

* Fix test sources
2025-09-08 18:46:41 -07:00
Matthew Zhou
531eb6afeb feat: Add project_id to message filtering/inserting to Turbopuffer [LET-4252] (#4466)
* Add project_id

* Fern autogen
2025-09-08 14:35:15 -07:00
Matthew Zhou
fb0e2d91a2 feat: Write tests for search messages [LET-4212] (#4447)
* Adjust naming

* Add testing and improve message search

* Adjust comments

* Change query text to query

* Fern autogen
2025-09-05 17:52:13 -07:00
Matthew Zhou
2e3cabc080 feat: Add search messages endpoint [LET-4144] (#4434)
* Add search messages endpoint

* Run fern autogen and fix tests
2025-09-05 14:28:27 -07:00
Matthew Zhou
fcfc40eaf2 feat: Add project id to message schema [LET-4166] (#4433)
* Add project id

* Propogate through update message by id async

* Add project id testing
2025-09-04 16:50:41 -07:00
Matthew Zhou
ba3843031e feat: Make end date inclusive on conversation search (#4431)
Make end date inclusive
2025-09-04 15:26:49 -07:00
Matthew Zhou
b8d403c962 feat: Add ranks to archival memory search [LET-4193] (#4426)
* Add ranks to archival memory search

* Fix test managers

* Fix archival memory test
2025-09-04 13:35:54 -07:00
Matthew Zhou
25d37e2ac9 fix: change to pure rank-based RRF for relevance ordering (#4411)
* Fix RRF

* Fix turbopuffer tests
2025-09-03 17:33:19 -07:00
Matthew Zhou
88831c7256 feat: Change namespace to be org scoped and filter on agent_id [LET-4163] (#4368)
* Change to org scoped and agent_id filtering

* Finish modifying conversation search tool

* Fix failing tests

* Get rid of bad imports
2025-09-03 10:00:19 -07:00
Matthew Zhou
75d444c335 feat: Extend crud lifecycle of messages [LET-4158] (#4364)
Extend crud lifecycle of messages
2025-09-02 14:38:30 -07:00
Matthew Zhou
00fd8617a6 feat: Add association for the vector namespace [LET-4148] (#4354)
Add association for the namespace
2025-09-02 13:21:42 -07:00
Matthew Zhou
20ac2923ff feat: Embed all messages in turbopuffer [LET-4143] (#4352)
* wip

* Finish embedding

* Fix ruff and tests
2025-09-02 12:43:48 -07:00
Matthew Zhou
335e0c2be1 feat: Support timestamp filtering for archival memories [LET-3469] (#4330)
Finish temporal filtering
2025-08-30 19:31:07 -07:00
Kian Jones
2b80b4aad8 chore: add tbpuf secrets and testing (#4292)
* add tbpuf secret

* deploy tbpuf key to prod deploy for core

* add secrets in staging and ci

* rn turbopuff test and add to integration test suite

* add tbpuf

* rename all occurences to tpuf

* remove debug prints

* buffer-puf

* add letta prefix

* add debug

* fix tests
2025-08-29 16:44:15 -07:00
Matthew Zhou
23b2769dc4 feat: Allow agent archival tools to insert/search with tags [LET-4072] (#4300)
* Finish modifying archival memory tools

* Add tags

* Add disabled test
2025-08-29 11:55:06 -07:00
Matthew Zhou
016feda83a feat: Support arbitrary string tagging filtering [LET-3467] (#4285)
* Finish tagging

* Add comprehensive tags functionality

* Add fern autogen

* Create passage tags table

* Add indices

* Add comments explaining dual storage

* Fix alembic heads

* Fix alembic

---------

Co-authored-by: Kian Jones <11655409+kianjones9@users.noreply.github.com>
2025-08-28 16:57:36 -07:00
Matthew Zhou
2791be982a feat: Add hybrid search on turbopuffer [LET-4096] (#4284)
Add hybrid search
2025-08-28 13:10:25 -07:00
Matthew Zhou
651671cb83 feat: Support basic upload/querying on tpuf [LET-3465] (#4255)
* wip implementing turbopuffer

* Move imports up

* Add type of archive

* Integrate turbopuffer functionality

* Debug turbopuffer tests failing

* Fix turbopuffer

* Run fern

* Fix multiple heads
2025-08-28 10:39:16 -07:00