anubhav77 commited on
Commit
d038f3c
·
1 Parent(s): 78c6359

Removing unnecessary files

Browse files
Files changed (3) hide show
  1. requirements.txt +1 -1
  2. server.py +0 -154
  3. types.py +0 -82
requirements.txt CHANGED
@@ -4,7 +4,7 @@ bs4
4
  lxml
5
  fastapi
6
  loguru
7
- chromadb
8
  langchain
9
  sentence_transformers
10
  sse_starlette
 
4
  lxml
5
  fastapi
6
  loguru
7
+ chromadb==0.3.26
8
  langchain
9
  sentence_transformers
10
  sse_starlette
server.py DELETED
@@ -1,154 +0,0 @@
1
- import chromadb
2
- from chromadb.config import Settings, System
3
- import time,json
4
- from pydantic import BaseModel
5
- from typing import List, Dict, Any, Generator, Optional, cast, Callable
6
- from chromadb.api.types import (
7
- Documents,
8
- Embeddings,
9
- EmbeddingFunction,
10
- IDs,
11
- Include,
12
- Metadatas,
13
- Where,
14
- WhereDocument,
15
- GetResult,
16
- QueryResult,
17
- CollectionMetadata,
18
- )
19
- from chromadb.errors import (
20
- ChromaError,
21
- InvalidUUIDError,
22
- InvalidDimensionException,
23
- )
24
- from chromadb.server.fastapi.types import (
25
- AddEmbedding,
26
- DeleteEmbedding,
27
- GetEmbedding,
28
- QueryEmbedding,
29
- RawSql, # Results,
30
- CreateCollection,
31
- UpdateCollection,
32
- UpdateEmbedding,
33
- )
34
- from chromadb.api import API
35
- from chromadb.config import System
36
- import chromadb.utils.embedding_functions as ef
37
- import pandas as pd
38
- import requests
39
- import json
40
- from typing import Sequence
41
- from chromadb.api.models.Collection import Collection
42
- import chromadb.errors as errors
43
- from uuid import UUID
44
- from chromadb.telemetry import Telemetry
45
- from overrides import override
46
-
47
-
48
- class client():
49
- def __init__(self):
50
- self.db = chromadb.Client(Settings(
51
- chroma_db_impl="duckdb+parquet",
52
- persist_directory="./index/chroma" # Optional, defaults to .chromadb/ in the current directory
53
- ))
54
-
55
- def heartbeat(self):
56
- return {"nanosecond heartbeat":int(time.time_ns())}
57
-
58
- def list_collections(self):
59
- return self.db.list_collections()
60
-
61
- def create_collection(
62
- self,
63
- name: str,
64
- metadata: Optional[CollectionMetadata] = None,
65
- embedding_function: Optional[EmbeddingFunction] = ef.DefaultEmbeddingFunction(),
66
- get_or_create: bool = False,
67
- ) -> Collection:
68
- col=self.db.create_collection(name,metadata=metadata,embedding_function=embedding_function,get_or_create=get_or_create)
69
- print(col)
70
- return col
71
-
72
- def get_collection(
73
- self,
74
- name: str,
75
- embedding_function: Optional[EmbeddingFunction] = ef.DefaultEmbeddingFunction()
76
- ) -> Collection:
77
- col=self.db.get_collection(name,embedding_function=embedding_function)
78
- print(col)
79
- return col
80
-
81
- def reset(self):
82
- return self.db.reset()
83
-
84
- def version(self):
85
- return self.db.get_version()
86
-
87
- def persist(self):
88
- return self.db.persist()
89
-
90
- def raw_sql(self,raw_sql: RawSql):
91
- return self.db.raw_sql(raw_sql.raw_sql)
92
-
93
- def add(self,ids: IDs,
94
- collection_id: UUID,
95
- embeddings: Embeddings,
96
- metadatas: Optional[Metadatas] = None,
97
- documents: Optional[Documents] = None,
98
- increment_index: bool = True,
99
- ) -> bool:
100
- return self.db._add(collection_id=collection_id,embeddings=embeddings,
101
- metadatas=metadatas,documents=documents,
102
- ids=ids,increment_index=increment_index)
103
-
104
- def update( self, collection_id: UUID, ids: IDs,
105
- embeddings: Optional[Embeddings] = None,
106
- metadatas: Optional[Metadatas] = None,
107
- documents: Optional[Documents] = None,
108
- ) -> bool:
109
- return self.db._update(ids=ids, collection_id=collection_id, embeddings=embeddings, documents=documents, metadatas=metadatas)
110
-
111
- def upsert( self, collection_id: UUID, ids: IDs,
112
- embeddings: Embeddings,
113
- metadatas: Optional[Metadatas] = None,
114
- documents: Optional[Documents] = None,
115
- increment_index: bool = True,
116
- ) -> bool:
117
- return self.db._upsert(collection_id=collection_id,embeddings=embeddings,metadatas=metadatas,documents=documents,ids=ids,increment_index=increment_index)
118
-
119
- def get( self, collection_id: UUID, ids: Optional[IDs] = None, where: Optional[Where] = {},
120
- sort: Optional[str] = None, limit: Optional[int] = None, offset: Optional[int] = None,
121
- page: Optional[int] = None, page_size: Optional[int] = None,
122
- where_document: Optional[WhereDocument] = {},
123
- include: Include = ["embeddings", "metadatas", "documents"],
124
- ) -> GetResult:
125
- return self.db._get(collection_id=collection_id, ids=ids, where=where,
126
- where_document=where_document, sort=sort, limit=limit,
127
- offset=offset, include=include)
128
- def delete( self, collection_id: UUID, ids: Optional[IDs],
129
- where: Optional[Where] = {}, where_document: Optional[WhereDocument] = {},
130
- ) -> IDs:
131
- return self.db._delete(where=where, ids=ids, collection_id=collection_id, where_document=where_document)
132
-
133
- def count(self, collection_id: UUID) -> int:
134
- return self.db._count(collection_id)
135
-
136
- def get_nearest_neighbors( self, collection_id: UUID, query_embeddings: Embeddings,
137
- n_results: int = 10, where: Where = {}, where_document: WhereDocument = {},
138
- include: Include = ["embeddings", "metadatas", "documents", "distances"],
139
- ) -> QueryResult:
140
- return self.db._query(collection_id=collection_id, where=where, where_document=where_document,
141
- query_embeddings=query_embeddings, n_results=n_results, include=include)
142
-
143
- def create_index(self, collection_name: str) -> bool:
144
- return self.db.create_index(collection_name)
145
-
146
- def modify( self, id: UUID, new_name: Optional[str] = None,
147
- new_metadata: Optional[CollectionMetadata] = None,
148
- ) -> None:
149
- """This is for updating the collection"""
150
- return self.db._modify(id=id, new_name=new_name, new_metadata=new_metadata)
151
-
152
- def delete_collection( self, name: str,) -> None:
153
- return self.db.delete_collection(name)
154
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
types.py DELETED
@@ -1,82 +0,0 @@
1
- from pydantic import BaseModel
2
- from typing import Any, Dict, List, Optional
3
- #from chromadb.api.types import (
4
- # CollectionMetadata,
5
- # Include,
6
- #)
7
- from typing import Union, Literal
8
-
9
- #TODO:Update version-Step1::This file is a copy from chromadb/server/fastapi/types.py
10
- # Copy CollectionMetadata and Include from chromadb.api.types and comment that import
11
- # Additionally import Union and Literal from typing for "Include to work"
12
- CollectionMetadata = Dict[Any, Any]
13
-
14
- Include = List[
15
- Union[
16
- Literal["documents"],
17
- Literal["embeddings"],
18
- Literal["metadatas"],
19
- Literal["distances"],
20
- ]
21
- ]
22
-
23
-
24
- class AddEmbedding(BaseModel): # type: ignore
25
- # Pydantic doesn't handle Union types cleanly like Embeddings which has
26
- # Union[int, float] so we use Any here to ensure data is parsed
27
- # to its original type.
28
- embeddings: Optional[List[Any]] = None
29
- metadatas: Optional[List[Dict[Any, Any]]] = None
30
- documents: Optional[List[str]] = None
31
- ids: List[str]
32
- increment_index: bool = True
33
-
34
-
35
- class UpdateEmbedding(BaseModel): # type: ignore
36
- embeddings: Optional[List[Any]] = None
37
- metadatas: Optional[List[Dict[Any, Any]]] = None
38
- documents: Optional[List[str]] = None
39
- ids: List[str]
40
- increment_index: bool = True
41
-
42
-
43
- class QueryEmbedding(BaseModel): # type: ignore
44
- # TODO: Pydantic doesn't bode well with recursive types so we use generic Dicts
45
- # for Where and WhereDocument. This is not ideal, but it works for now since
46
- # there is a lot of downstream validation.
47
- where: Optional[Dict[Any, Any]] = {}
48
- where_document: Optional[Dict[Any, Any]] = {}
49
- query_embeddings: List[Any]
50
- n_results: int = 10
51
- include: Include = ["metadatas", "documents", "distances"]
52
-
53
-
54
- class GetEmbedding(BaseModel): # type: ignore
55
- ids: Optional[List[str]] = None
56
- where: Optional[Dict[Any, Any]] = None
57
- where_document: Optional[Dict[Any, Any]] = None
58
- sort: Optional[str] = None
59
- limit: Optional[int] = None
60
- offset: Optional[int] = None
61
- include: Include = ["metadatas", "documents"]
62
-
63
-
64
- class RawSql(BaseModel): # type: ignore
65
- raw_sql: str
66
-
67
-
68
- class DeleteEmbedding(BaseModel): # type: ignore
69
- ids: Optional[List[str]] = None
70
- where: Optional[Dict[Any, Any]] = None
71
- where_document: Optional[Dict[Any, Any]] = None
72
-
73
-
74
- class CreateCollection(BaseModel): # type: ignore
75
- name: str
76
- metadata: Optional[CollectionMetadata] = None
77
- get_or_create: bool = False
78
-
79
-
80
- class UpdateCollection(BaseModel): # type: ignore
81
- new_name: Optional[str] = None
82
- new_metadata: Optional[CollectionMetadata] = None