Skip to content

OCIEmbeddings hardcodes input_type="SEARCH_QUERY" on embed_query → 1024-dim vectors, breaks RAG against SEARCH_DOCUMENT-indexed (1536-dim) tables when using cohere.embed-v4.0 #292

@fede-kamel

Description

@fede-kamel

Summary

locus.rag.embeddings.oci.OCIEmbeddings.embed_query() (around line 370 in 0.2.0b25) hardcodes input_type="SEARCH_QUERY" on the underlying EmbedTextDetails request, ignoring self.oci_config.input_type.

For cohere.embed-v4.0 on OCI Generative AI, the two input_types return different output dimensions:

input_type output dim
SEARCH_DOCUMENT 1536
SEARCH_QUERY 1024

(This asymmetry is OCI/Cohere v4 behaviour, not Locus's fault — but it interacts badly with the hardcoded override.)

embed_documents() correctly uses SEARCH_DOCUMENT, so an ingestion path that calls embed_documents populates a vector column at 1536 dim. Then a search via embed_query returns a 1024-dim vector. VECTOR_DISTANCE(embedding /*1536*/, :qvec /*1024*/, COSINE) raises:

ORA-12801: error signaled in parallel query server P000, instance 1
ORA-51803: Vector dimension count must match the dimension count
specified in the column definition (expected 1536 dimensions,
specified 1024 dimensions).

Net result: every RAG query against a v4-indexed table errors out, with no warning at config / startup time.

Reproduction

import asyncio
from locus.rag import OCIEmbeddings, OracleVectorStore, RAGRetriever
from locus.rag.embeddings.oci import OCIEmbeddingConfig

async def main():
    e = OCIEmbeddings(
        oci_config=OCIEmbeddingConfig(
            model_id="cohere.embed-v4.0",
            compartment_id="…",
            profile_name="DEFAULT",
            input_type="SEARCH_DOCUMENT",      # explicit; ignored at query time
        )
    )
    r = await e.embed_query("luxury hotels in Greece")
    print(len(r.embedding))   # → 1024  (expected 1536)

asyncio.run(main())

A retriever built on top of this against a VECTOR(1536, FLOAT32) table errors at search time with the ORA-12801 above.

Affected code

  • locus/rag/embeddings/oci.py:370 (or thereabouts) — embed_details = EmbedTextDetails(... input_type="SEARCH_QUERY", ...) inside embed_query().

Suggested fix

Two non-exclusive options:

  1. Honor self.oci_config.input_type when set: only fall through to "SEARCH_QUERY" when the user hasn't supplied one. Lets callers pin both embed_documents and embed_query to the same input_type when they need matching dims.

    input_type = self.oci_config.input_type if self.oci_config.input_type else "SEARCH_QUERY"
  2. Expose output_dimensions on OCIEmbeddingConfig: Cohere v4 in OCI accepts output_dimensions on the embed request; OCI's EmbedTextDetails exposes it. Letting callers pin a target dim (e.g. 1024 or 1536) makes the request symmetric regardless of input_type.

Either fix unblocks v4-indexed RAG. The first is the smaller change.

Environment

  • locus-sdk[oci,server] 0.2.0b25
  • oci 2.176.0
  • cohere.embed-v4.0 via OCI Generative AI, us-chicago-1
  • Oracle 26ai (Autonomous Database, free tier), VECTOR(1536, FLOAT32) + HNSW cosine index
  • Python 3.13

Related

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