Skip to content
TheChatArchiveThe Chat Archive
o3-2025-04-16· OpenAIHugging Face LMArena Human Preference 140K

can I use any embedding model for opensearch vector database ?

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-opus-4-20250514’s answer.
  1. User

    can I use any embedding model for opensearch vector database ?

  2. Assistant

    Short answer
    Yes—OpenSearch does not care where the numbers come from. If you can turn your data into a fixed-length float array, you can index it and run k-NN search.

    Long(er) answer
    Below are the practical details and caveats that usually trip people up.

    ─────────────────────

    1. What OpenSearch actually stores
      ───────────────────── • A vector is just a float[] field.
      • You pick one of two field types:
    Field typeTypical useDim. limit*Ann. search engine
    dense_vectorExact or small-scale ANN1024Lucene
    knn_vectorLarge-scale ANN16 384HNSW via nmslib / Faiss

    *Limits are as of 2.9; check your version.

    ───────────────────── 2. Any embedding model works ───────────────────── • Create vectors with OpenAI, Sentence-Transformers, Cohere, self-hosted models, etc.
    • The only thing that must match your index mapping is the dimension (length).
    • Vectors must be float32 (Python np.float32 or list of loose floats).

    ───────────────────── 3. Generating the vectors ───────────────────── Three common options:

    A. Generate outside OpenSearch (most common)

    from sentence_transformers import SentenceTransformer
    import numpy as np, opensearchpy as osp
    
    model = SentenceTransformer("all-MiniLM-L6-v2")  # 384-d
    doc = "Vector search is awesome"
    vec = model.encode(doc).astype(np.float32).tolist()
    
    client = osp.OpenSearch("http://localhost:9200")
    client.index(index="my-kb", body={"text": doc, "vector": vec})
    

    B. Use the OpenSearch ML plugin (2.4+)
    ‣ Register a Hugging Face model once, then call _infer to embed inside the cluster.
    ‣ Good when you want everything in one place, but it does use cluster resources.

    C. Call a serverless/remote inference endpoint (SageMaker, Bento, etc.) from your ingest pipeline.

    ───────────────────── 4. Creating an index mapping ───────────────────── Example with HNSW (cosine):

    PUT my-kb
    {
      "settings": {
        "index": { "knn": true }
      },
      "mappings": {
        "properties": {
          "text":   { "type": "text" },
          "vector": {
            "type": "knn_vector",
            "dimension": 384,
            "method": {
              "name": "hnsw",
              "space_type": "cosinesimil",
              "engine": "faiss",
              "parameters": { "ef_construction": 512, "m": 16 }
            }
          }
        }
      }
    }
    

    ───────────────────── 5. Running a search ─────────────────────

    POST my-kb/_search
    {
      "size": 5,
      "query": {
        "knn": {
          "vector": {
            "vector": [/* your 384-d query vector */],
            "k": 5
          }
        }
      }
    }
    

    Mix with standard filters (must, should) to get hybrid search.

    ───────────────────── 6. Practical gotchas ───────────────────── • Same dimension everywhere: trying to index a 768-d vector into a 384-d field → 400 error.
    • Vector size vs performance: higher dimension = more RAM + slower indexing/search.
    • Similarity metric:
    – cosinesimil or l2 for knn_vector;
    – cosine, dot_product, l2_norm for dense_vector (Lucene).
    • Model license ≠ OpenSearch license. Check if you’re allowed to store/share those embeddings.
    • Upgrading versions: k-NN plugin settings sometimes change (Faiss vs nmslib).

    ───────────────────── 7. When “any model” is not ideal ───────────────────── • If you need cross-modal (image + text) search, ensure the embedding model puts both modalities into the same space.
    • For multilingual use, pick a model trained for that (e.g., distiluse-base-multilingual-v2).
    • Extremely large vectors (>16 k) are technically possible with custom plug-ins but are not recommended.

    ───────────────────── Key take-away ───────────────────── OpenSearch is model-agnostic. Choose the embedding model that best represents your data, make sure you know the dimension and similarity metric, and feed the resulting float array into a dense_vector or knn_vector field. That’s it. Happy searching! 🚀

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.