Spaces:
Sleeping
Sleeping
File size: 2,071 Bytes
287a0bc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Prior to running the below make sure that you have an HF server running:\n",
"\n",
"You can run:\n",
"\n",
"```bash\n",
"docker compose -f examples/server_side_embeddings/huggingface/docker-compose.yml up -d\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/Users/tazarov/experiments/chroma-experiments/1367_hugging_face_embedding_server\n"
]
}
],
"source": [
"%cd ../../../"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'ids': [['test']],\n",
" 'distances': [[0.0]],\n",
" 'embeddings': None,\n",
" 'metadatas': [[None]],\n",
" 'documents': [['test']],\n",
" 'uris': None,\n",
" 'data': None}"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import chromadb\n",
"\n",
"from chromadb.utils.embedding_functions import HuggingFaceEmbeddingServer\n",
"\n",
"\n",
"ef = HuggingFaceEmbeddingServer(url=\"http://localhost:8001/embed\")\n",
"\n",
"client = chromadb.HttpClient(\"http://localhost:8000/\")\n",
"\n",
"col=client.get_or_create_collection(\"test\",embedding_function=ef)\n",
"\n",
"col.add(documents=[\"test\"],ids=[\"test\"])\n",
"\n",
"col.query(query_texts=[\"test\"])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|