Embedding Seems Unsuccessful for Chroma + OpenAI
Labels: name: area: embeddings, name: area: vector store, name: auto:bug

### System Info

openai==0.27.7
langchain==0.0.237
chromadb==0.4.2

Platform: Windows 11
Python Version: 3.10

### Who can help?

_No response_

### Information

- [ ] The official example notebooks/scripts
- [X] My own modified scripts

### Related Components

- [ ] LLMs/Chat Models
- [X] Embedding Models
- [ ] Prompts / Prompt Templates / Prompt Selectors
- [ ] Output Parsers
- [ ] Document Loaders
- [X] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

Within this file, I was expecting db_collection to have embeddings when it was printed. However, the output is like this:

> db_collection {'ids': ['1234_5678_1'], 'embeddings': None, 'metadatas': [{'source': 'Test0720.txt'}], 'documents': ['Nuclear power in the United States is provided by 99 commercial reactors with a net capacity of 100,350 megawatts (MW), 65 pressurized water reactors and 34 boiling water reactors.\n\nIn 2016 they produced a total of 805.3 terawatt-hours of electricity, which accounted for 19.7% of the nation's total electric energy generation.\n\nIn 2016, nuclear energy comprised nearly 60 percent of U.S. emission-free generation.']}

The value for "embeddings" is empty.

Here is the code:

```
import os
from flask import Blueprint, request, jsonify
from werkzeug.utils import secure_filename
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.text_splitter import CharacterTextSplitter
from langchain.vectorstores import Chroma
from langchain.document_loaders import TextLoader


chroma_bp = Blueprint('chroma_bp', __name__, url_prefix='/v1/resource')

openai_key = os.getenv('OPENAI_API_KEY')
os.environ["OPENAI_API_KEY"] = openai_key


@chroma_bp.route('/save_to_chroma', methods=['POST'])
def api_handler():
    file = request.files['file']
    user_id = request.form.get('user_id')
    file_id = request.form.get('file_id')

    try:
        response = create_chroma_db_from_file(file, file_id, user_id)
        return jsonify({'response': 'Chroma DB created successfully'}), 200
    except Exception as e:
        print(f"Exception: {e}")  # Debug print statement
        return jsonify({'error': str(e)}), 500


def create_chroma_db_from_file(file, file_id, user_id):
    filename = secure_filename(file.filename)
    file.save(filename)

    # load the document and split it into chunks
    loader = TextLoader(filename)
    documents = loader.load()

    # split it into chunks
    text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
    docs = text_splitter.split_documents(documents)
    print(f"Number of documents: {len(docs)}")
    print(f"Documents:", docs)

    # # create the open-source embedding function
    embeddings = OpenAIEmbeddings(openai_api_key=openai_key)

    # load it into Chroma

    ids = [f"{file_id}_{user_id}_{i}" for i in range(1, len(docs) + 1)]
    db = Chroma.from_documents(
        documents=docs, embedding=embeddings, ids=ids, persist_directory="../chromadb")
    print(f"db", db)
    print(f"db_collection", db._collection.get(ids=[ids[0]]))
    db.persist()

    # query it
    query = "Nuclear power in the United States is provided by 99 commercial reactors with a net capacity of 100,350 megawatts (MW), 65 pressurized water reactors and 34 boiling water reactors. In 2016 they produced a total of 805.3 terawatt-hours of electricity, which accounted for 19.7% of the nation's total electric energy generation. In 2016, nuclear energy comprised nearly 60 percent of U.S. emission-free generation."
    search_result = db.similarity_search(query)

    # print results
    print(search_result[0].page_content)

    os.remove(filename)

    return True

```

### Expected behavior

The embedding is done successfully and could be shown in logs. Thank you!