{ "cells": [ { "cell_type": "code", "execution_count": 2, "id": "fbcdfea8-7241-46d7-a771-c0381a3e7063", "metadata": {}, "outputs": [], "source": [ "# imports\n", "\n", "import os\n", "import re\n", "import math\n", "import json\n", "from tqdm import tqdm\n", "import random\n", "from dotenv import load_dotenv\n", "from huggingface_hub import login\n", "import numpy as np\n", "import pickle\n", "from openai import OpenAI\n", "from sentence_transformers import SentenceTransformer\n", "from datasets import load_dataset\n", "import chromadb\n", "from items import Item\n", "from testing import Tester\n", "import pandas as pd\n", "import numpy as np\n", "from sklearn.ensemble import RandomForestRegressor\n", "from sklearn.linear_model import LinearRegression\n", "from sklearn.metrics import mean_squared_error, r2_score\n", "import joblib\n" ] }, { "cell_type": "code", "execution_count": 3, "id": "e6e88bd1-f89c-4b98-92fa-aa4bc1575bca", "metadata": {}, "outputs": [], "source": [ "# CONSTANTS\n", "\n", "QUESTION = \"How much does this cost to the nearest dollar?\\n\\n\"\n", "DB = \"products_vectorstore\"" ] }, { "cell_type": "code", "execution_count": 4, "id": "98666e73-938e-469d-8987-e6e55ba5e034", "metadata": {}, "outputs": [], "source": [ "# environment\n", "\n", "load_dotenv()\n", "os.environ['OPENAI_API_KEY'] = os.getenv('OPENAI_API_KEY', 'your-key-if-not-using-env')\n", "os.environ['HF_TOKEN'] = os.getenv('HF_TOKEN', 'your-key-if-not-using-env')" ] }, { "cell_type": "code", "execution_count": 5, "id": "dc696493-0b6f-48aa-9fa8-b1ae0ecaf3cd", "metadata": {}, "outputs": [], "source": [ "# Load in the test pickle file:\n", "\n", "with open('test.pkl', 'rb') as file:\n", " test = pickle.load(file)" ] }, { "cell_type": "code", "execution_count": 6, "id": "d26a1104-cd11-4361-ab25-85fb576e0582", "metadata": {}, "outputs": [], "source": [ "client = chromadb.PersistentClient(path=DB)\n", "collection = client.get_or_create_collection('products')" ] }, { "cell_type": "code", "execution_count": 8, "id": "e00b82a9-a8dc-46f1-8ea9-2f07cbc8e60d", "metadata": {}, "outputs": [], "source": [ "result = collection.get(include=['embeddings', 'documents', 'metadatas'])\n", "vectors = np.array(result['embeddings'])\n", "documents = result['documents']\n", "prices = [metadata['price'] for metadata in result['metadatas']]" ] }, { "cell_type": "code", "execution_count": 9, "id": "48894777-101f-4fe5-998c-47079407f340", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
RandomForestRegressor(n_jobs=8, random_state=42)In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
RandomForestRegressor(n_jobs=8, random_state=42)