#If I try to embed multiple strings the embeddings come out in a single float instead of many floats.

1 messages Ā· Page 1 of 1 (latest)

worldly dawn
#

I am not sure what I am doing wrong, I am not an expert I am just a university student (with basic formal education in python) who's studies aren't related to AI but I am growing this skill on the side. With that being said, I am trying to build a (personal) RAG system to answer questions from the content of books of my choosing.
The way I am going about is by parsing the .pdf or .epub file and save each chapter in a Document object, I then chunk each chapter using the llama_index sentence splitter into TextNodes with some metadata.

Here is where I think the mistake most likely is but I am not sure what. Because Cohere embed connection point requires the text argument to be a list of strings, so I use this line to add the texts from the TextNodes to a list: texts = [node.text for node in text_nodes] and then
response = co.embed(
texts= texts,
model="embed-multilingual-v3.0",
input_type="search_document",
embedding_types=["float"],
)

When I check either response or response.embeddings, I get 1 float with all the embeddings in a single list like in the attached picture. I hope this is enough context but if I am missing something important please let me know. Thank you in advance.

forest trail
#

Hey there thanks for reaching us! šŸ‘‹

This is an expected behaviour actually!

  1. Your approach for preparing the text is correct:

    • Parsing PDFs/EPUBs into chapters
    • Chunking into TextNodes
    • Creating a list of texts for embedding
  2. When you call co.embed(), Cohere returns embeddings for each text in your input list. The response contains a list of embeddings where:

    • essentially embeddings are high-dimensional vector (typically 1024 dimensions for our models) these are vectors (numbers) that only the model can understand.
    • When you generate embeddings, you get one embedding per input text
    • each embedding represents the semantic meaning of its corresponding text chunk

To use these embeddings in your RAG system:

  1. Store each embedding alongside its corresponding text chunk perferably in a vector database
  2. When you have a query, embed it using the same model but with input_type="search_query" Note: there are different kind of embeddings but search_query is the one used on the query that the user provides! So if you're confused feel free to ask us ā¤ļø
  3. Use vector similarity (cosine similarity is common) to find the most relevant chunks

Here's a guide and example of how to use the embeddings: https://docs.cohere.com/v2/docs/embeddings

Don't worry if this seems complex, you're already on the right track! šŸ˜‰ The embeddings you're getting are working as intended, and now it's just a matter of using them effectively in your retrieval system. ā¤ļø