Skip to content

Commit f0f9c02

Browse files
committed
Data retrival using LLM, RAG and Agentic
0 parents  commit f0f9c02

23 files changed

+902
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/mvnw text eol=lf
2+
*.cmd text eol=crlf

.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
HELP.md
2+
target/
3+
.mvn/wrapper/maven-wrapper.jar
4+
!**/src/main/**/target/
5+
!**/src/test/**/target/
6+
7+
### STS ###
8+
.apt_generated
9+
.classpath
10+
.factorypath
11+
.project
12+
.settings
13+
.springBeans
14+
.sts4-cache
15+
16+
### IntelliJ IDEA ###
17+
.idea
18+
*.iws
19+
*.iml
20+
*.ipr
21+
22+
### NetBeans ###
23+
/nbproject/private/
24+
/nbbuild/
25+
/dist/
26+
/nbdist/
27+
/.nb-gradle/
28+
build/
29+
!**/src/main/**/build/
30+
!**/src/test/**/build/
31+
32+
### VS Code ###
33+
.vscode/
34+
/.venv/
35+
/my_chroma_data/

DataRetrieval_using_AgenticRAG.png

237 KB
Loading

DataRetrieval_using_LLM.png

63.8 KB
Loading

DataRetrieval_using_RAG.png

206 KB
Loading

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
LLM, RAG, Agentic RAG Example
2+
=============================
3+
4+
Purpose
5+
-------
6+
This repository contains `agentic-rag`, a Spring Boot application that demonstrates an integration between Spring AI (OpenAI model bindings) and a vector store (Chroma).
7+
8+
Explanation - Query Options
9+
---------------------------
10+
Query with LLM:-
11+
----------------
12+
![screenshot](DataRetrieval_using_LLM.png)
13+
14+
Query with RAG:-
15+
---------------
16+
![screenshot](DataRetrieval_using_RAG.png)
17+
18+
Query with Agentic RAG:-
19+
------------------------
20+
![screenshot](DataRetrieval_using_AgenticRAG.png)
21+
22+
Prerequisites
23+
-------------
24+
- JDK 21
25+
- Maven 3.8+ (or the bundled Maven wrapper `mvnw` / `mvnw.cmd`)
26+
- Network access to your OpenAI-compatible endpoint and Chroma (vector store)
27+
28+
Run
29+
-------
30+
```
31+
mvn clean spring-boot:run
32+
```
33+
34+
Recommended environment variables (example)
35+
-------------------------------------------
36+
- OPENAI_KEY — API key for your OpenAI-compatible provider
37+
- CHROMADB_API_KEY — API key (if your Chroma deployment requires it)
38+
- CHROMADB_DEFAULT_DATABASE — database name used by the Chroma client
39+
- CHROMADB_TENANT_NAME — tenant name used by the Chroma client
40+
41+
Troubleshooting checklist (Chroma I/O error example)
42+
---------------------------------------------------
43+
------------------------------------------
44+
If you see an I/O error similar to:
45+
46+
I/O error on GET request for "http://localhost:8000/api/v2/tenants/default_tenant/databases/default_database/collections/"
47+
48+
Do the following in order:
49+
1. Confirm your effective configuration: `spring.ai.vectorstore.chroma.client.host` and `port` in `application.yaml` or runtime env vars.
50+
2. If those values are unset, set them or supply the environment variables listed above.
51+
3. Ensure the Chroma service is reachable from the host running the app (firewall, VPN, Docker network). Use `curl` or `Invoke-WebRequest` for a quick check.
52+
4. If using a cloud/managed provider, confirm the API key and endpoint are correct and not expired.
53+
5. Review application logs: the Chroma client will log connection attempts and stack traces when failing.
54+
55+
Next steps / Enhancements
56+
------------------------
57+
- Add automated integration tests that spin up a test Chroma instance (or mock the vector-store) to prevent regressions.
58+
- Add a clear `docker-compose` for local development that can bring up a vector-store + app for dev teams.
59+
60+

chroma/amazon_return_policy.txt

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
Amazon Return Policy
2+
Easy shopping, simple returns - that's our promise. At Amazon, we're committed to making your shopping experience as seamless and worry-free as possible. We understand that there may be times when a purchase may not meet your expectations or your needs might change. When that happens, we make completing a return simple and convenient.
3+
Most items can be returned for a refund or replacement/exchange within 30 days of delivery as long as they are in original or unused condition. For eligible items, you can enjoy free returns at many locations near you. For information on an item's return eligibility, please check the product detail page before placing your order. After placing an order, you can find relevant information on an item's return eligibility in your Order History.
4+
A refund will be provided if Amazon (or the third party seller) has received the item, and determined that you are eligible for a refund. It can take up to 30 days for us to receive and process your return. In certain circumstances refund timeframes may be longer. If we need additional information about your return, we will notify you with instructions to contact Customer Service. For more information, please see our Refunds page.
5+
Refund Timelines
6+
Once we issue your refund, it may take additional time for your financial institution to make funds available in your account.
7+
Refund Timeline Refund Method
8+
2-3 hours Amazon.com Gift Card or Gift Card balance
9+
3-5 business days Credit Card
10+
Up to 5 business days Shop with Reward Points
11+
Up to 10 business days Debit card
12+
Checking account
13+
EBT Card
14+
Cash (at participating locations)
15+
Up to 30 days Pre-paid credit card (depending on the issuer of the card)
16+
No refund issued Promotional certificate
17+
Return Window
18+
Most items sold on Amazon.com can be returned within 30 days of delivery - some exceptions include:
19+
20+
7 days
21+
Digital books accidentally purchased from the Kindle Store that have not been read.
22+
Digital textbooks, workbooks, and other educational content that have not been downloaded.
23+
Songs or albums accidentally purchased from our Digital Music Store using Alexa
24+
15 days
25+
Apple Brand products and Boost Infinite Brand products sold in new condition (AppleCare+ plans may be canceled in accordance with the terms of the plan)
26+
Items sold in the Amazon Haul store that are over $3 (Haul items less than $3 are non-returnable and non-refundable).
27+
90 days
28+
Amazon Renewed products in "Acceptable", "Good", or "Excellent" condition types.
29+
Most nonperishable Baby products
30+
Items purchased from an Amazon Birthday and/or Custom Gift List by someone other than the registry owner.
31+
Mattresses (excluding crib mattresses)
32+
180 days
33+
Items purchased from an Amazon Wedding Registry by someone other than the registry owner.
34+
365 days
35+
Amazon Renewed products in "Premium" condition
36+
Items purchased from an Amazon Baby Registry by someone other than the registry owner.
37+
Items That You Can't Return
38+
Some products are non-returnable, such as the following:
39+
40+
Perishables
41+
Products that may pose potential health and safety risks once sold
42+
Products with shipping restrictions
43+
Customized products made specifically for you
44+
Redeemable products
45+
Amazon Pharmacy products
46+
Pet medication products
47+
Certain digital products
48+
Automobiles
49+
Additionally, products listed as "Final Sale" are non-returnable and non-refundable, including trading card games, specific discounted items, and items sold in the Amazon Haul store that are $3 and less.
50+
51+
In the unlikely event that a non-returnable/Final Sale item arrives damaged, defective, or materially different from what was ordered, please contact Customer Service.
52+
53+
Initiating a Return
54+
To initiate a return on a item that's eligible for return, simply go to Your Orders and click on "Return Items" button next to the item. Detail instructions can be found in this video.
55+
56+
Third Party Seller Returns
57+
When you order from a third-party seller that fulfills and ships their own inventory, your return is sent back to the seller instead of Amazon. Sellers must offer one of the following:
58+
59+
A return address within the United States where you can ship the item
60+
A prepaid return label; or
61+
A full refund without requesting the item be returned
62+
If a third-party seller doesn't offer these methods to return your items, please file an A-to-z Guarantee claim. For more information about returns to sellers, please refer to Returns to Third-Party Sellers.
63+
64+
Sending Us Your Return
65+
You can return most items for free at over 8,000 convenient locations, typically within a 5-mile radius of your address. Additionally, most returns do not need to be boxed or labeled. Please make sure, however, that your item is returned in original or unused condition with tags attached and hygiene seals and liners intact, and in the original manufacturer's packaging including tags, components, accessories, manuals, certificates of authenticity, and other inserts.
66+
67+
Please follow the return instructions for each item to receive a refund. Do not include items from separate orders in the same return.
68+
69+
If you have bought an item (e.g., computers, electronics) on which you've saved personal information, please erase this information completely by following manufacturer instructions.
70+
71+
Amazon Pharmacy
72+
Items purchased from Amazon Pharmacy are not returnable or refundable. For more details or further assistance with an Amazon Pharmacy item, please see the Amazon Pharmacy Help Page.
73+
74+
75+
Amazon Business
76+
This return policy also applies to purchases made through your Amazon Business account. For the return policies on special Amazon Business programs such as Spot Buys made through the Custom Quote feature, please consult the Amazon Business Accounts Terms and Conditions and Feature Terms and Conditions. Contact Amazon Business for more help.
77+
78+
Amazon Luxury Stores
79+
For more information on Luxury Stores items, or if there are any issues with your Luxury Stores purchase, please visit our Luxury Stores Help Page.
80+
81+
Return Fees
82+
While returns are generally free, certain situations or item conditions may incur fees. Note that an item cannot be sent back to you after it has been returned (except certain Luxury Stores items that incur 100% damage fees).
83+
84+
Fee Description Amount
85+
Return Shipping Fee Most items include at least one free return shipping option, but some shipping/drop-off options come with an additional fee. Amazon may also charge a fee if you have an unusually high return rate. Varies by item and the shipping method selected
86+
Late fee If you do not drop off or complete a carrier pick-up on or before the "return by date" once a return has been started. 20% of the item price
87+
Damage fee If you return an item that is damaged, missing parts, not in original condition, has tags removed or have obvious signs of use for reasons not due to an Amazon.com or seller error. Up to 50% of the item price, except for Luxury Stores items which will be charged 100% of item price.
88+
Restocking Fee If you return an item from any of the following product types:
89+
Software and video games that are opened, activated, used, or missing parts.
90+
Opened collectible cards, board games/table top games, collectible/chase variant figurines
91+
100% of the item price
92+
Returning a Gift
93+
Navigate to the Returns page, use the 17-digit order number e.g. 123-1234567-1234567 (add: "how do I find this?" hover-over link) on your packing slip that came with your item or on the digital gift receipt, to initiate a return. If you can't locate the order number, ask the gift giver. If you need an exchange or replacement, you'll need to return the gift and place a new order.
94+
95+
Kindle books you receive as a gift are eligible for exchange for an Amazon.com Gift Card before acceptance.
96+
Global Store Returns
97+
Items shipped from Amazon.com, including Amazon Resale, can be returned within 30 days of delivery, with some exceptions:
98+
99+
For most Amazon Global Store returns, you will be provided with a pre-paid UPS return label which allows you to return the item(s) to any UPS drop-off point located across the US. You can find your most convenient UPS location using the following link: https://www.ups.com/dropoff/?loc=en_US
100+
Not all Global Store products are eligible for a pre-paid return. In this case, you will need to return the item at your own expense. We recommend you return the item(s) using a trackable method at the carrier of your choice.
101+
It can take up to 25 days for an item to reach us once you return it. Once the item is received and processed at our fulfillment center, it takes 2 business days for the refund to be processed and 3-5 business days for the refund amount to show up in your account.
102+
Amazon will automatically refund up to $20 for return postage costs on receipt of the item. If your return postage costs exceed $20, you may contact Customer Service to request a refund of the remaining postage cost. If you return a defective, damaged or incorrect item, you'll be refunded the full postage cost, as well as your Import Fees Deposit, once your return is processed.
103+
Special Delivery Service Returns
104+
Items delivered with "Deluxe Delivery & Unpack" and "Deluxe Delivery & Assembly" services qualify for instant return at the point of delivery. Please visit our Special Delivery Options page for more details.
105+
106+
Product Warranties
107+
Please contact the manufacturer directly for product registration and warranty-related information. A manufacturer warranty may not cover used products offered on Amazon.com; review the manufacturer warranty details on the product detail page for coverage or contact the manufacturer directly.
108+
109+
Unintended Item(s) in My Return
110+
If you accidentally sent the wrong item to Amazon, please contact Customer Service as soon as possible. Note that we may not be able to locate mistakenly sent items and are unable to provide compensation in these cases. Amazon does not store items sent in error and will handle (and/or dispose) such items at our discretion.
111+
112+
Returning Items Purchased in a Bundle
113+
You must return all items purchased in a Bundle with Savings to receive a refund. Partial refunds are not available.
114+
115+
Note:
116+
117+
Amazon offers a convenient return service for reasonable use by our customers. Should customers abuse this service, we may adjust its availability.
118+
119+
For any return, Amazon may require additional information and documentation (such as a government-issued photo identification) during the processing of a return to help determine whether to provide a refund/replacement. Amazon reserves the right to take additional actions to prevent fraud or abuse (including denial of returns, refunds or exchanges, or, imposing return fees). Amazon may modify this policy at any time.

chroma/chroma_client_setup.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import chromadb
2+
import uuid
3+
from chromadb.config import Settings
4+
5+
##"sentence-transformers/all-MiniLM-L6-v2
6+
7+
client = chromadb.HttpClient(
8+
host="localhost",
9+
port=8000,
10+
ssl=False,
11+
headers=None,
12+
tenant="default_tenant",
13+
database="default_database",
14+
settings=Settings(allow_reset=True, anonymized_telemetry=False)
15+
)
16+
17+
print(client.heartbeat())
18+
print('chroma_client', client)
19+
20+
collection = client.get_or_create_collection(name="amazon_return_policy",
21+
metadata={"description": "Amazon Return Policy Document Collection"})
22+
print('collection', collection)
23+
24+
with open("amazon_return_policy.txt", "r", encoding="utf-8") as f:
25+
amazon_return_policy:list[str] = f.read().splitlines()
26+
27+
collection.add(
28+
ids=[str(uuid.uuid4()) for _ in amazon_return_policy],
29+
documents=amazon_return_policy,
30+
metadatas=[{"line": line} for line in range(len(amazon_return_policy))]
31+
)
32+
print('Data added to collection successfully.')
33+
34+
print(client.heartbeat())
35+

chroma/chroma_cloud_setup.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import chromadb
2+
import uuid
3+
4+
chroma_client = chromadb.CloudClient(
5+
api_key='${CHROMADB_API_KEY}',
6+
tenant='${CHROMADB_TENANT_NAME}',
7+
database=${CHROMADB_DEFAULT_DATABASE}
8+
)
9+
10+
print('chroma_client', chroma_client)
11+
12+
collection = chroma_client.get_or_create_collection(name="amazon_return_policy",
13+
metadata={"description": "Amazon Return Policy Document Collection"})
14+
print('collection', collection)
15+
16+
with open("amazon_return_policy.txt", "r", encoding="utf-8") as f:
17+
amazon_return_policy:list[str] = f.read().splitlines()
18+
19+
collection.add(
20+
ids=[str(uuid.uuid4()) for _ in amazon_return_policy],
21+
documents=amazon_return_policy,
22+
metadatas=[{"line": line} for line in range(len(amazon_return_policy))]
23+
)
24+
print('Data added to collection successfully.')
25+
print(collection.peek())

chroma/chroma_data.png

259 KB
Loading

0 commit comments

Comments
 (0)