# "Vector dimension 8 does not match the dimension of the index 1536"

**URL:** <https://community.pinecone.io/t/vector-dimension-8-does-not-match-the-dimension-of-the-index-1536/4638>\
**Category:** Support\
**Tags:** vector-database, embeddings\
**Created:** [February 22, 2024, 8:05pm UTC](https://community.pinecone.io/t/vector-dimension-8-does-not-match-the-dimension-of-the-index-1536/4638 "2024-02-22T20:05:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![garciafaciog](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/garciafaciog/32/2072_2.png) [@garciafaciog](https://community.pinecone.io/u/garciafaciog)\
**Post date:** [February 22, 2024, 8:05pm UTC](https://community.pinecone.io/t/vector-dimension-8-does-not-match-the-dimension-of-the-index-1536/4638/1 "2024-02-22T20:05:07Z")

</div>

I am working with Pinecone where I have already made the embeddings for my information. Now, I have this code to help my chatbot refine the questions and provide the answers. Initially, I encountered a problem with not being able to make the embeddings due to a mismatch between the dimensions of Pinecone (1536) and the model I was using. Currently, I use text-embedding-ada-002 which, according to my research, matches the dimensions, as it also supports 1536. Now when I run my chatbot, I encounter this new error:

**“Vector dimension 8 does not match the dimension of the index 1536”**

I don’t understand where it comes from and I’m not able to resolve it. Any ideas?

```auto
from sentence_transformers import SentenceTransformer
from transformers import GPT2TokenizerFast
import pinecone
import openai
import streamlit as st
openai.api_key = "API_KEY"
model = GPT2TokenizerFast.from_pretrained('Xenova/text-embedding-ada-002')

pinecone.init(api_key='API_KEY', environment='gcp-starter')
index = pinecone.Index('test')

def find_match(input):
    input_em = list(model.encode(input))
    result = index.query(input_em, top_k=2, includeMetadata=True)
    return result['matches'][0]['metadata']['text']+"\n"+result['matches'][1]['metadata']['text']

def query_refiner(conversation, query):
    response = openai.completions.create(
    model="gpt-3.5-turbo-instruct",
    prompt=f"Given the following user query and conversation log, formulate a question that would be the most relevant to provide the user with an answer from a knowledge base.\n\nCONVERSATION LOG: \n{conversation}\n\nQuery: {query}\n\nRefined Query:",
    temperature=0.7,
    max_tokens=256,
    top_p=1,
    frequency_penalty=0,
    presence_penalty=0
    )
    return response.choices[0].text

def get_conversation_string():
    conversation_string = ""
    for i in range(len(st.session_state['responses'])-1):
        
        conversation_string += "Human: "+st.session_state['requests'][i] + "\n"
        conversation_string += "Bot: "+ st.session_state['responses'][i+1] + "\n"
    return conversation_string

```

---

<div class="post-metadata">

**Author:** ![Cory\_Pinecone](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/cory_pinecone/32/1712_2.png) [@Cory\_Pinecone](https://community.pinecone.io/u/Cory_Pinecone)\
**Post date:** [February 23, 2024, 9:20am UTC](https://community.pinecone.io/t/vector-dimension-8-does-not-match-the-dimension-of-the-index-1536/4638/2 "2024-02-23T09:20:10Z")

</div>

Hi @garciafaciog. Just to clarify, Pinecone does not have a set dimensionality for indexes. You can set it to be whatever you need it to be when you create the index. 1536 happens to be the most common because that’s used by OpenAI’s Ada002, but if you’re using a model that only has 8 dimensions, you’ll need to create an index that also uses 8 dimensions.

You can double-check the dimensionality of your model by just running a simple `len()` on the `input_em` and confirm whether it’s returning 8 or 1536 dimensions.

Also, you might want to upgrade your Python client to the 3.0 version as it comes with a number of improvements. It will require some refactoring of your code to make use of, though. For instance, there’s no longer an `init()` method, you just instantiate a `Pinecone` object directly. I recommend reviewing our [migration guide](https://canyon-quilt-082.notion.site/Pinecone-Python-SDK-v3-0-0-Migration-Guide-056d3897d7634bf7be399676a4757c7b) prior to running the upgrade.

```auto
pip install -U pinecone-client

```

---

<div class="post-metadata">

**Author:** ![Jasper](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/jasper/32/4514_2.png) [@Jasper](https://community.pinecone.io/u/Jasper)\
**Post date:** [February 23, 2024, 9:21am UTC](https://community.pinecone.io/t/vector-dimension-8-does-not-match-the-dimension-of-the-index-1536/4638/3 "2024-02-23T09:21:35Z")

</div>

Hi @garciafaciog

check the length of this variable you are querying by. I think this line might be the problem. I don’t think .encode will create a list of correct length for your query. Run it in debug and see long long the input\_em variable is.

> [@garciafaciog](#):
>
> `input_em = list(model.encode(input))`

Hope this helps

---

<div class="post-metadata">

**Author:** ![garciafaciog](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/garciafaciog/32/2072_2.png) [@garciafaciog](https://community.pinecone.io/u/garciafaciog)\
**Post date:** [February 27, 2024, 8:10pm UTC](https://community.pinecone.io/t/vector-dimension-8-does-not-match-the-dimension-of-the-index-1536/4638/4 "2024-02-27T20:10:27Z")

</div>

Hi, cory!

I have reviewed according to your recommendations, which confirms that indeed, there is no match between the dimensions of my vectors and my index. Taking this into account, is there something I can do from my Pinecone code to specify that I want my **vectors** to have a dimension of 384, for example?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/pinecone/original/1X/d16664eba369eeee623700cf12feab5562b37eaf.jpeg) [@system](https://community.pinecone.io/u/system)\
**Post date:** [March 12, 2024, 8:11pm UTC](https://community.pinecone.io/t/vector-dimension-8-does-not-match-the-dimension-of-the-index-1536/4638/5 "2024-03-12T20:11:03Z")

</div>

Closed on March 12, 2024, 8:11pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
