Repository navigation
Description
Thank you for 1.0, and for the quick fix to title ranking in #1957.
Summary
Voyage's contextualized chunk embedding models (voyage-context-4) embed all chunks of one document together, so a chunk that never names its subject (for example "Its budget grew by 15%") still carries the document's context. Basic Memory already splits notes into vector chunks, which is the situation these models are designed for.
At the moment these models cannot be used through the LiteLLM provider. LiteLLM sends any Voyage model whose name contains context to POST /v1/contextualizedembeddings, which expects one inner list of chunks per document and returns the vectors in the same nested shape. Basic Memory sends a flat List[str] and reads a flat response, so indexing is rejected and search fails while parsing the response.
Environment
- basic-memory 0.24.1 (LiteLLM 1.91.5), SQLite backend, Windows 11
semantic_embedding_provider = "litellm",semantic_embedding_document_input_type = "document",semantic_embedding_query_input_type = "query"(Voyage models have no default input types in_default_input_types, so I set them)- I also read the v1.0.0 source:
LiteLLMEmbeddingProvider._embedstill sends a flatinputbatch and readsembeddingfrom each response item, so I expect the same behaviour on 1.0. I have not run 1.0 itself yet.
Reproduction
Synthetic text, same call shape as _embed:
import asyncio, litellm
CHUNKS = ["Project Atlas is a quarterly planning note.",
"Its budget grew by 15% compared to the previous quarter."]
async def main():
# search path: flat list + input_type="query"
r = await litellm.aembedding(model="voyage/voyage-context-4",
input=["What happened to the Atlas budget?"],
input_type="query", drop_params=True)
print(r.data[0]) # nested item: object, data, index; no "embedding" key
# indexing path: flat list + input_type="document"
await litellm.aembedding(model="voyage/voyage-context-4", input=CHUNKS,
input_type="document", drop_params=True)
asyncio.run(main())| Call | Result |
|---|---|
flat list, input_type="document" (indexing path) |
Rejected. Voyage returns List[str] inputs requires enable_auto_chunking=True or input_type='query', which LiteLLM raises as APIConnectionError (status_code 500) |
flat list, no input_type (the default for Voyage models) |
Rejected with the same message |
flat list, input_type="query" (search path) |
The call succeeds, but each response item is nested (object, data, index) with no embedding key, so the parsing in _embed raises KeyError: 'embedding' |
nested [CHUNKS], input_type="document", through LiteLLM |
The call succeeds; the response has the same nested shape |
direct REST call, nested [CHUNKS], input_type="document" |
HTTP 200, two chunk embeddings |
Proposal
When the configured model is a contextualized model (LiteLLM's own check is "context" in model.lower() in litellm/llms/voyage/embedding/transformation_contextual.py):
- Indexing: send each note's chunks as one inner list (
List[List[str]],input_type="document") and flattendata[i].data[j].embeddingback into chunk order. As far as I can tell,embed_documentsreceives a flat list today, and one flush batch can contain chunks from several notes, so the grouping would have to be passed down from the vector sync. I'm not sure which layer you would prefer for that. - Search: send the query as a one-element inner list and read the nested response in the same way.
- Limits: Voyage allows at most 1,000 inputs (documents) and 16K chunks per request. Without auto-chunking, the total across all inputs is capped at 32K tokens; 120K applies only with
enable_auto_chunking(this is from the footnote to the model table in Voyage's contextualized embeddings guide; the API reference page lists only 120K). So batches would need to split between notes, and a note longer than 32K tokens would need a fallback, such as embedding its chunks in several groups or using the non-contextual path. - Identity:
litellm_embedding_identityalready includes the model name, so switching models already re-embeds. Any new grouping or fallback option that changes the vectors would need to be added there as well.
A smaller first step that would help with any embedding model: an option to prepend the note title and heading path to each body chunk before embedding. Observation and relation rows already include the title, but body chunks after the first one do not, and continuation chunks of a long section also lose their heading. Since chunk keys hash the chunk text (#1691), the added context would also need to be part of the key, so that vectors refresh when a title or heading changes.
If #1806 ends up replacing LiteLLM with direct provider adapters, a Voyage adapter might be the natural place for the nested input.
I'd be glad to discuss which of these fits before anyone writes code, as CONTRIBUTING asks.
Why it matters
Notes often refer back to their own subject ("this case", "the second embodiment", "the vendor"), and many of my notes share template sentences, so their body chunks look alike to the embedding model. Issue #1335 (closed; the entity body is no longer split per bullet) described the same gap: chunks after the first lacked the note's title and permalink. In 1.0 this is still the case for long body rows.
Notes
- I have not measured retrieval quality with
voyage-context-4, because indexing is rejected. I have a pre-registered retrieval eval (about 570 notes and about 1,100 questions, hit@5 and MRR@5, run on 0.24.1) and can share aggregate numbers if that would help. - I have not tested the Postgres backend.
- I'm happy to test a branch on Windows.
Activity
phernandez commentedon Nov 3, 2026
Thanks for the detailed repro. Deferring this one for now.
LiteLLM stays an optional dependency (
basic-memory[litellm]). Any contextualized-embedding support has to live inside the LiteLLM provider and must not make LiteLLM required. The hard part is passing each note's chunk grouping down through vector sync batches, since one flush batch can mix chunks from several notes. A contained PR along those lines is welcome.