ragxo 0.1.6__py3-none-any.whl → 0.1.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
ragxo/client.py CHANGED
@@ -20,7 +20,26 @@ class Document(BaseModel):
20
20
  id: int
21
21
 
22
22
  class Ragxo:
23
+ """
24
+ A RAG (Retrieval-Augmented Generation) system that combines vector search with LLM responses.
25
+
26
+ Attributes:
27
+ dimension (int): Dimension of the embedding vectors
28
+ collection_name (str): Name of the Milvus collection
29
+ db_path (str): Path to the Milvus database
30
+ processing_fn (list): List of preprocessing functions
31
+ embedding_fn (Callable): Function to generate embeddings
32
+ system_prompt (str): System prompt for LLM
33
+ model (str): LLM model name
34
+ """
35
+
23
36
  def __init__(self, dimension: int) -> None:
37
+ """
38
+ Initialize the Ragxo instance.
39
+
40
+ Args:
41
+ dimension (int): Dimension of the embedding vectors
42
+ """
24
43
  self.dimension = dimension
25
44
  self.collection_name = "ragx"
26
45
  os.makedirs("ragx_artifacts", exist_ok=True)
@@ -34,28 +53,105 @@ class Ragxo:
34
53
  self.model = "gpt-4o-mini"
35
54
 
36
55
  def add_preprocess(self, fn: Callable) -> Self:
56
+ """
57
+ Add a preprocessing function to the pipeline.
58
+
59
+ Args:
60
+ fn (Callable): Function that takes and returns a string
61
+
62
+ Returns:
63
+ Self: The current instance for method chaining
64
+ """
37
65
  self.processing_fn.append(fn)
38
66
  return self
39
67
 
40
68
  def add_llm_response_fn(self, fn: Callable) -> Self:
69
+ """
70
+ Add a function to process LLM responses.
71
+
72
+ Args:
73
+ fn (Callable): Function to process LLM responses
74
+
75
+ Returns:
76
+ Self: The current instance for method chaining
77
+ """
41
78
  self.llm_response_fn = fn
42
79
  return self
43
80
 
44
81
  def add_embedding_fn(self, fn: Callable) -> Self:
82
+ """
83
+ Set the embedding function for vector generation.
84
+
85
+ Args:
86
+ fn (Callable): Function that converts text to embeddings
87
+
88
+ Returns:
89
+ Self: The current instance for method chaining
90
+
91
+ Raises:
92
+ ValueError: If fn is None
93
+ """
45
94
  if not fn:
46
95
  raise ValueError("Embedding function cannot be None")
47
96
  self.embedding_fn = fn
48
97
  return self
49
98
 
50
99
  def add_system_prompt(self, prompt: str) -> Self:
100
+ """
101
+ Set the system prompt for LLM interactions.
102
+
103
+ Args:
104
+ prompt (str): System prompt text
105
+
106
+ Returns:
107
+ Self: The current instance for method chaining
108
+ """
51
109
  self.system_prompt = prompt
52
110
  return self
53
111
 
54
- def add_model(self, model: str) -> Self:
112
+ def add_model(self, model: str, limit: int = 10,
113
+ temperature: float = 0.5,
114
+ max_tokens: int = 1000,
115
+ top_p: float = 1.0,
116
+ frequency_penalty: float = 0.0,
117
+ presence_penalty: float = 0.0) -> Self:
118
+ """
119
+ Configure the LLM model and its parameters.
120
+
121
+ Args:
122
+ model (str): Name of the LLM model
123
+ limit (int): Maximum number of results to return from vector search
124
+ temperature (float): Sampling temperature
125
+ max_tokens (int): Maximum tokens in response
126
+ top_p (float): Nucleus sampling parameter
127
+ frequency_penalty (float): Frequency penalty parameter
128
+ presence_penalty (float): Presence penalty parameter
129
+
130
+ Returns:
131
+ Self: The current instance for method chaining
132
+ """
55
133
  self.model = model
134
+ self.limit = limit
135
+ self.temperature = temperature
136
+ self.max_tokens = max_tokens
137
+ self.top_p = top_p
138
+ self.frequency_penalty = frequency_penalty
139
+ self.presence_penalty = presence_penalty
56
140
  return self
57
141
 
58
142
  def index(self, data: list[Document]) -> Self:
143
+ """
144
+ Index documents into the vector database.
145
+
146
+ Args:
147
+ data (list[Document]): List of documents to index
148
+
149
+ Returns:
150
+ Self: The current instance for method chaining
151
+
152
+ Raises:
153
+ ValueError: If embedding function is not set
154
+ """
59
155
  if not self.embedding_fn:
60
156
  raise ValueError("Embedding function not set")
61
157
 
@@ -83,6 +179,20 @@ class Ragxo:
83
179
  return self
84
180
 
85
181
  def query(self, query: str, output_fields: list[str] = ['text', 'metadata'], limit: int = 10) -> list[list[dict]]:
182
+ """
183
+ Search the vector database for similar documents.
184
+
185
+ Args:
186
+ query (str): Search query
187
+ output_fields (list[str]): Fields to return in results
188
+ limit (int): Maximum number of results
189
+
190
+ Returns:
191
+ list[list[dict]]: Search results
192
+
193
+ Raises:
194
+ ValueError: If embedding function is not set
195
+ """
86
196
  if not self.embedding_fn:
87
197
  raise ValueError("Embedding function not set. Please call add_embedding_fn first.")
88
198
 
@@ -240,17 +350,23 @@ class Ragxo:
240
350
  raise
241
351
 
242
352
  def generate_llm_response(self,
243
- query: str,
244
- limit: int = 10,
245
- data: list[dict] = None,
246
- temperature: float = 0.5,
247
- max_tokens: int = 1000,
248
- top_p: float = 1.0,
249
- frequency_penalty: float = 0.0,
250
- presence_penalty: float = 0.0,
251
- ) -> ChatCompletion:
353
+ query: str,
354
+ data: list[dict] = None) -> ChatCompletion:
355
+ """
356
+ Generate LLM response based on query and retrieved data.
357
+
358
+ Args:
359
+ query (str): User query
360
+ data (list[dict], optional): Retrieved documents. If None, performs a new query
361
+
362
+ Returns:
363
+ ChatCompletion: LLM response
364
+
365
+ Raises:
366
+ ValueError: If system prompt is not set
367
+ """
252
368
  if data is None:
253
- data = self.query(query, limit=limit)[0]
369
+ data = self.query(query, limit=self.limit)[0]
254
370
 
255
371
  if not self.system_prompt:
256
372
  raise ValueError("System prompt not set. Please call add_system_prompt first.")
@@ -261,11 +377,11 @@ class Ragxo:
261
377
  {"role": "system", "content": self.system_prompt},
262
378
  {"role": "user", "content": "query: {} data: {}".format(query, data)}
263
379
  ],
264
- temperature=temperature,
265
- max_tokens=max_tokens,
266
- top_p=top_p,
267
- frequency_penalty=frequency_penalty,
268
- presence_penalty=presence_penalty,
380
+ temperature=self.temperature,
381
+ max_tokens=self.max_tokens,
382
+ top_p=self.top_p,
383
+ frequency_penalty=self.frequency_penalty,
384
+ presence_penalty=self.presence_penalty,
269
385
  )
270
386
 
271
387
  return response
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ragxo
3
- Version: 0.1.6
3
+ Version: 0.1.8
4
4
  Summary: A RAG (Retrieval-Augmented Generation) toolkit with Milvus integration
5
5
  Home-page: https://github.com/yourusername/ragx
6
6
  License: MIT
@@ -20,9 +20,11 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
20
  Requires-Dist: boto3 (>=1.36.14,<2.0.0)
21
21
  Requires-Dist: dill (>=0.3.9,<0.4.0)
22
22
  Requires-Dist: milvus (>=2.3.9,<3.0.0)
23
+ Requires-Dist: mocker (>=1.1.1,<2.0.0)
23
24
  Requires-Dist: openai (>=1.61.1,<2.0.0)
24
25
  Requires-Dist: pydantic (>=2.10.6,<3.0.0)
25
26
  Requires-Dist: pymilvus (>=2.5.4,<3.0.0)
27
+ Requires-Dist: pytest-mock (>=3.14.0,<4.0.0)
26
28
  Project-URL: Repository, https://github.com/yourusername/ragx
27
29
  Description-Content-Type: text/markdown
28
30
 
@@ -65,7 +67,7 @@ def preprocess_text_remove_special_chars(text: str) -> str:
65
67
  return re.sub(r'[^a-zA-Z0-9\s]', '', text)
66
68
 
67
69
  def get_embeddings(text: str) -> list[float]:
68
- return openai.embeddings.create(text=text, model="text-embedding-ada-002").data[0].embedding
70
+ return openai.embeddings.create(input=text, model="text-embedding-ada-002").data[0].embedding
69
71
 
70
72
  ragxo_client = Ragxo(dimension=768)
71
73
 
@@ -74,7 +76,14 @@ ragxo_client.add_preprocess(preprocess_text_remove_special_chars)
74
76
  ragxo_client.add_embedding_fn(get_embeddings)
75
77
 
76
78
  ragxo_client.add_system_prompt("You are a helpful assistant that can answer questions about the data provided.")
77
- ragxo_client.add_model("gpt-4o-mini")
79
+ ragxo_client.add_model(
80
+ "gpt-4o-mini",
81
+ temperature=0.5,
82
+ max_tokens=1000,
83
+ top_p=1.0,
84
+ frequency_penalty=0.0,
85
+ presence_penalty=0.0
86
+ )
78
87
 
79
88
  ragxo_client.index([
80
89
  Document(text="Capital of France is Paris", metadata={"source": "example"}, id=1),
@@ -92,16 +101,10 @@ ragxo_client.export("my_rag_v1.0.0")
92
101
  ```python
93
102
  loaded_ragxo_client = Ragxo.load("my_rag_v1.0.0")
94
103
 
95
- results = loaded_ragxo_client.query("What is the capital of France?")
104
+ vector_search_results = loaded_ragxo_client.query("What is the capital of France?")
96
105
 
97
106
  llm_response = loaded_ragxo_client.generate_llm_response(
98
- "What is the capital of France?",
99
- limit=10,
100
- temperature=0.5,
101
- max_tokens=1000,
102
- top_p=1.0,
103
- frequency_penalty=0.0,
104
- presence_penalty=0.0)
107
+ "What is the capital of France?")
105
108
 
106
109
  ```
107
110
 
@@ -0,0 +1,5 @@
1
+ ragxo/__init__.py,sha256=0VVe-z4XkkGQLQIG0hF0Hyf87_RgX0E4T9TRwwTkbmE,68
2
+ ragxo/client.py,sha256=5AvARwpm4ux-7nWRLs4k5lDFhkgbjl6B9yNjdxcK8vo,12766
3
+ ragxo-0.1.8.dist-info/METADATA,sha256=4uo_8ewStWVyYQYtpfktLz9i8jVfQPReeZxAxfhrWQ4,6227
4
+ ragxo-0.1.8.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
5
+ ragxo-0.1.8.dist-info/RECORD,,
@@ -1,5 +0,0 @@
1
- ragxo/__init__.py,sha256=0VVe-z4XkkGQLQIG0hF0Hyf87_RgX0E4T9TRwwTkbmE,68
2
- ragxo/client.py,sha256=M4777mj6oPdRIm9TvqIwXoQuJUMc7Ywczlykutd6c70,9068
3
- ragxo-0.1.6.dist-info/METADATA,sha256=1W4vJeY0awkXbtM0o3dyhFRHEY8VLHwkXrm55KECbg4,6141
4
- ragxo-0.1.6.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
5
- ragxo-0.1.6.dist-info/RECORD,,
File without changes